コンテンツにスキップ

p-json

json モジュールはJSONのパースとシリアライズ関数を提供します。

use p-json as j

JSON文字列をパースし、対応する値を返します。

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

値をJSON文字列に変換します。

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}

値を整形されたJSON文字列に変換します。indent はインデントのスペース数を指定します(デフォルト: 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
-- }