As suggested by @hostilefork using the inverse operation shows us how it works.
>> load-json {{"labels": [ {"label": "one"}, {"label": "two"} ]}}
== make object! [
labels: [
make object! [
label: "one"
]
make object! [
label: "two"
]
]
]
So we need to create an object containing objects. compose/deep
is needed to evaluate the nested (
)
so the objects are created.
to-json make object! compose/deep [
labels: [
(make object! [ label: "one" ])
(make object! [ label: "two" ])
]
]
In addition to the object!
approach there is another option with a simpler syntax:
>> to-json [
<labels> [
[ <label> "one" ]
[ <label> "two" ]
]
]
== {{"labels":[{"label":"one"},{"label":"two"}]}}