🔍

json.o

Library for JSON serialization. Converts O language data structures into JSON format strings.

Main element

Name Description / comments
json[<x>] Serialize any O value to JSON string

Examples

Numbers:

o)load[getenv[`OHOME];"json"];
o)json[42]
"42"
o)json[3.14]
"3.14"

Strings:

o)json["hello world"]
"\"hello world\""

Arrays:

o)json[1 2 3 4 5]
"[1,2,3,4,5]"
o)json["red" "green" "blue"]
"[\"red\",\"green\",\"blue\"]"

Boolean values:

o)json[1b]
"true"
o)json[0b]
"false"

Null:

o)json[0N0]
""

Dictionaries:

o)json[`name`age`city!("Alice";25;"Paris")]
"{name:\"Alice\",age:25,city:\"Paris\"}"

Nested dictionaries:

o)d: `user`data!("John";`age`city!(30;"NYC"));
o)json[d]
"{user:\"John\",data:{age:30,city:\"NYC\"}}"

Tables:

o)t: +`a`b!(1 2 3;4 5 6);
o)json[t]
"{a:[1,2,3],b:[4,5,6]}"

Lists:

o)json[(1;2;3)]
"[1,2,3]"
o)json[(42;"hello";1b)]
"[42,\"hello\",true]"

Auxiliary elements

Name Description / comments
array[<x>] Convert O array to JSON array format
jsmap[<x>] Convert O dictionary/table to JSON object format