Skip to content

p-json

The json module provides JSON parsing and serialization functions.

use p-json as j

Parses a JSON string and returns the corresponding value.

use p-json as j
const data be j.parse[//;{"name": "Purus", "version": 1};//]
console.log[data.name] -- "Purus"

Converts a value to a JSON string.

use p-json as j
const obj be [name be //;Purus;//, version be 1]
const text be j.stringify[obj]
console.log[text] -- {"name":"Purus","version":1}

Converts a value to a pretty-printed JSON string. The indent parameter specifies the number of spaces (default: 2).

use p-json as j
const obj be [name be //;Purus;//, version be 1]
console.log[j.prettify[obj]]
-- {
-- "name": "Purus",
-- "version": 1
-- }
console.log[j.prettify[obj; 4]]
-- {
-- "name": "Purus",
-- "version": 1
-- }