29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
scope # JSON encode/decode - translation of the Phix sample, using Agena's standard json module
|
|
|
|
import json;
|
|
|
|
print( "roundtrip (10 examples):" );
|
|
|
|
local constant json_strings := [ '{"this":"that","age":{"this":"that","age":29}}'
|
|
, '1'
|
|
, '"hello"'
|
|
, 'null'
|
|
, '[12]'
|
|
, '[null,12]'
|
|
, '[]'
|
|
, '{"this":"that","age":29}'
|
|
, '{}'
|
|
, '[null,[null,12]]'
|
|
];
|
|
|
|
for i to size json_strings do
|
|
local constant s := json_strings[ i ];
|
|
local constant j := json.decode( s );
|
|
local constant r := json.encode( j );
|
|
local constant pad := if size s < 29 then 30 else size s + 1 fi;
|
|
print( " " & strings.ljustify( s, pad ) & " -> "
|
|
, j, "\n" & if s = r then "-> " else "** " fi & r & "\n"
|
|
)
|
|
od
|
|
end
|