Skip to main content
Module

x/pure_json/mod.ts>parse

Pure version of built-in JSON Object
Latest
function parse
import { parse } from "https://deno.land/x/pure_json@1.0.0-beta.1/mod.ts";

Safe converts a JavaScript Object Notation (JSON) string into an object. It does not throw errors compared to JSON.parse.

Parameters

text: string

A valid JSON string.

optional
reviver: Parameters<JSON.parse>[1]

A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is.

import { parse } from "https://deno.land/x/pure_json@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std@$VERSION/testing/asserts.ts";

const [data, err] = parse(`{ "hello": "world"}`);

assertEquals(err, undefined);
assertEquals(data, { hello: "world" });

Returns

[json, undefined] | [undefined, SyntaxError]