JSON and Rebol

Comprehensive functions for exchanging data from Rebol/Red to JSON serial formats.  To get started, enter the following into the Rebol Console or paste into a Rebol script:

do http://reb4.me/r/altjson

At the Console, both functions include basic usage information:

? load-json
? to-json

to-json

This function will serialise Rebol values to a JSON string.  ‘to-json is fairly agressive at converting unsupported datatypes to strings:

>> to-json ["A" "block" of 6.0 Rebol #values]
== {["A","block","of",6.0,"Rebol","values"]}

‘to-json will attempt to resolve GET-WORD! values:

>> foo: ["Foo" "Bar"]
>> to-json [baz: :foo]
== {{"baz":["Foo","Bar"]}}

load-json

This function will attempt to decode JSON-formatted data:

>> probe load-json {{"foo":"bar","num":10,"null":null}}
make object! [
foo: "bar"
num: 10
null: none
]

Alternate usage with the /flat refinement will allow you to parse the resultant Rebol values.  Object keys are imported as tag! types:

>> probe load-json/flat {{"foo":"bar","num":1.0}}
[
<foo> "bar"
<num> 1.0
]