Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/pure_json/stringify.ts>default

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

Safe converts a JavaScript value to a JavaScript Object Notation (JSON) string.

Parameters

value: unknown

A JavaScript value, usually an object or array, to be converted.

optional
replacer: (number | string)[] | null

An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.

optional
space: string | number

Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

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

const cycle: Record<string, unknown> = {};
cycle[""] = cycle;

const [data, err] = JSON.stringify(cycle);

assertIsError(err, TypeError);
assertEquals(data, undefined);

Returns

[string, undefined] | [undefined, TypeError]