Module

x/atlas_sdk3/mod.ts>EJSON.stringify

TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy
Latest
function EJSON.stringify
import { EJSON } from "https://dotland.deno.dev/x/atlas_sdk3@v0.3.1/mod.ts";
const { stringify } = EJSON;

Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

Examples

Example 1

const { EJSON } = require('bson');
const Int32 = require('mongodb').Int32;
const doc = { int32: new Int32(10) };

// prints '{"int32":{"$numberInt":"10"}}'
console.log(stringify(doc, { relaxed: false }));

// prints '{"int32":10}'
console.log(stringify(doc));

Parameters

  • The value to convert to extended JSON
optional
replacer: (number | string)[] | ((
this: any,
key: string,
value: any,
) => any) | Options
  • A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
optional
space: string | number
  • A String or Number object that's used to insert white space into the output JSON string for readability purposes.
optional
options: Options
  • Optional settings

Returns

string