Jump to content

JSON: Difference between revisions

857 bytes added ,  5 months ago
m
(JSON in FreeBASIC)
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 3 users not shown)
Line 335:
 
Bracmat and JSON/Javascript do far from represent data in similar ways.
Bracmat has arbitrary-precision arithmetic. Floating point numbers are not a native datatype in Bracmat. (But since 2023, Bracmat has an object type, UFP, that handles floating point operations using C "double"s.)
Bracmat has no Boolean values <code>true</code> and <code>false</code> and no <code>null</code> value.
Bracmat has arrays and objects, but they are second class citizens. Most data is best represented as binary tree structures, with binary operators like the plus, comma, dot or white space sitting in the nodes and the atomic parts of the data sitting in the leaves.
Line 2,180:
'{"age":5,"name":"pojo"}'
</pre>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(var object {:a 1 :b "Hello, world!" [1 2 3] :c}
serialised (to-json object)
deserialised (from-json serialised))
 
(print "Object: " object)
(print "Serialised: " serialised)
(str "Deserialised: " deserialised)
</syntaxhighlight>
 
{{out}}
 
<pre>
Object: {:a 1, :b "Hello, world!", [1 2 3] :c}
Serialised: {":a":1,":b":"Hello, world!","[1 2 3]":":c"}
Deserialised: {":a" 1, ":b" "Hello, world!", "[1 2 3]" ":c"}
</pre>
 
Observe that JSON is incapable of lossless serialisation and deserialisation of Insitux data structures, with the recommended approach rather being [https://www.rosettacode.org/wiki/Object_serialization#Insitux <code>str</code> and <code>safe-eval</code>].
 
=={{header|J}}==
Line 4,036 ⟶ 4,058:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var json = require('JSON::PP').new;
var data = json.decode('{"blue": [1, 2], "ocean": "water"}');
say data;
data{:ocean} = Hash.new(water => %w[fishy salty]);
say json.encode(data);</syntaxhighlight>
{{out}}
<pre>Hash.new(
'"blue'" => [1, 2],
'"ocean'" => '"water'"
)
)
{"blue":[1,2],"ocean":{"water":["fishy","salty"]}}</pre>
 
Line 4,653 ⟶ 4,675:
=={{header|Wren}}==
{{libheader|Wren-json}}
<syntaxhighlight lang="ecmascriptwren">import "/json" for JSON
 
var s = "{ \"foo\": 1, \"bar\": [ \"10\", \"apples\"] }"
9,476

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.