Thanks to visit codestin.com
Credit goes to oxlib.sh

Skip to content

Json

Utility functions for working with JSON (with support for bigint).

Examples

Below are some examples demonstrating common usages of the Json module:

Stringifying JSON

JSON values can be stringified (with bigint support) using Json.stringify:

import { Json } from 'ox'
 
const json = Json.stringify({
  foo: 'bar',
  baz: 69420694206942069420694206942069420694206942069420n,
})
'{"foo":"bar","baz":69420694206942069420694206942069420694206942069420}'

Parsing JSON

JSON values can be parsed (with bigint support) using Json.parse:

import { Json } from 'ox'
 
const value = Json.parse('{"foo":"bar","baz":69420694206942069420694206942069420694206942069420}')
{ foo: 'bar', baz: 69420694206942069420694206942069420694206942069420n }

Functions

NameDescription
Json.canonicalizeSerializes a value to a canonical JSON string as defined by RFC 8785 (JSON Canonicalization Scheme).
Json.parseParses a JSON string, with support for bigint.
Json.stringifyStringifies a value to its JSON representation, with support for bigint.