::requires "json.cls")
See Wikipedia https://en.wikipedia.org/wiki/JSON (2026-10-18, "wikipedia.json")
{
"first_name": "John",
"last_name": "Smith",
"is_alive": true,
"age": 27,
"address": {
"street_address": "21 2nd Street",
"city": "New York",
"state": "NY",
"postal_code": "10021-3100"
},
"phone_numbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [
"Catherine",
"Thomas",
"Trevor"
],
"spouse": null
}json_01.rex
json_01.rex
-- ooRexx 5.1 or higher
parse arg fn -- get file name
o = .json~fromJsonFile(fn) -- reads and unencodes JSON file
say .json~toJson(o,.true) -- encode as legible (human-friendly) JSON string
say "---"
say .json~toJson(o) -- encode as minimized (standard) JSON string
::requires "json.cls" -- get access to the JSON class
“rexx json_01.rex wikipedia.json”
rexx json_01.rxj wikipedia.json
Output (note attributes are sorted by name to ease locating them):
wikipedia.json
{
"first_name": "John",
"last_name": "Smith",
"is_alive": true,
"age": 27,
"address": {
"street_address": "21 2nd Street",
"city": "New York",
"state": "NY",
"postal_code": "10021-3100"
},
"phone_numbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [
"Catherine",
"Thomas",
"Trevor"
],
"spouse": null
}{
"address": {
"city": "New York",
"postal_code": "10021-3100",
"state": "NY",
"street_address": "21 2nd Street"
},
"age": 27,
"children": [
"Catherine",
"Thomas",
"Trevor"
],
"first_name": "John",
"is_alive": true,
"last_name": "Smith",
"phone_numbers": [
{
"number": "212 555-1234",
"type": "home"
},
{
"number": "646 555-4567",
"type": "office"
}
],
"spouse": null
}---
{"address":{"city":"New
York","postal_code":"10021-3100","state":"N
Y","street_address":"21 2nd
Street"},"age":27,"children":["Catherine","
Thomas","Trevor"],"first_name":"John","is_a
live":true,"last_name":"Smith","phone_numbe
rs":[{"number":"212
555-1234","type":"home"},{"number":"646
555-4567","type":"office"}],"spouse":null}
Minimal (standard):
– no white space characters
– no carriage-return characters
– no line-feed characters
json_02.rex
json_02.rex
rel = .relation~new -- create a relation (allows duplicates)
rel["WU"]="Vienna Business University"
rel["Wien"]= ("Vienna", "Vienne") -- English, French
rel["historical districts"] = .list~of(1190, 1090, 1020)
rel["currently in district"] = 1020
rel["is older than Harvard"] = .json~false -- a JSON false value
say .json~toJson(rel) -- encode as minimized JSON (standard)
say "---"
say .json~toJson(rel,.true)-- encode as legible JSON (human friendly)
::requires "json.cls" -- get access to the JSON class
{"WU":"Vienna Business University","Wien":["Vienna","Vienne"],
"currently in district":1020,"historical districts":[1190,1090,
1020],"is older than Harvard":false}
---
{
"WU": "Vienna Business University",
"Wien": [
"Vienna",
"Vienne"
],
"currently in district": 1020,
"historical districts": [
1190,
1090,
1020
],
"is older than Harvard": false
}WU
Prof. Mag. Dr. Rony G. Flatscher
Welthandelsplatz 1
1020 Wien/Vienna
Austria/Europe
www: www.wu.ac.at