JSON encoding for boolean
gregit opened this issue · 5 comments
gregit commented
Hello,
I would expect the boolean key to be encoded as a JSON boolean instead of text.
current result as of 3.18.0:
>> encode 'json to-map [text: "text" boolean: true integer: 6]
== {{"text":"text","boolean":"true","integer":6}}
expected:
== {{"text":"text","boolean":true,"integer":6}}
Oldes commented
Actually in your example the boolean
value is not logic, but word!
>> encode 'json to-map [text: "text" boolean: #(true) integer: 6 none: #(none) word: foo]
== {{"text":"text","boolean":true,"integer":6,"none":null,"word":"foo"}}
Oldes commented
>> encode 'json reduce ['true true]
== {["true",true]}
Oldes commented
Also... when you are using a to-map
(which is just a function wrapper around to map!
), you may want to use to-json
instead of encode 'json ...
.
>> import json
>> ? to-json
USAGE:
TO-JSON data
DESCRIPTION:
Convert Rebol data to a JSON string.
TO-JSON is a #(function!) value.
ARGUMENTS:
data [any-type!]
REFINEMENTS:
/pretty
indent [string!] Pretty format the output, using given indentation.
/ascii Force ASCII output (instead of UTF-8)
gregit commented
Thanks, just tried to-json but it doesn't really do what I'd like:
>> to-json [text: "text" boolean: #(true) integer: 6 none: #(none) word: foo]
= {["text:","text","boolean:",true,"integer:",6,"none:",null,"word:","foo"]}
Oldes commented
I don't have an idea what you would like... it converts a value into a JSON format. In you case above it converts a block...
>> to-json 1
== "1"
>> to-json [1 2]
== "[1,2]"
>> to-json #[foo: 1]
== {{"foo":1}}