JSON: Difference between revisions

2,856 bytes added ,  5 months ago
m
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 5 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 1,678:
end program json_fortran
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
{{libheader|YAJL}}
[https://github.com/mrozbarry/fbjson FreeBASIC JSON Parser] "JSON is simple, so the interface should also be simple" Written by Oz (alex DOT barry AT gmail DOT com) - April 22, 2010, Updated May 21, 2013
 
Sample JSON file:
<syntaxhighlight>{
"menu": { "id": "file",
"string": "File:",
"number": -3,
"boolean1":true , "boolean2" :false,"boolean3":true,
"sentence" : "the rain in spain falls mainly on the plain. This here \" is an escaped quote!",
"null": null,
"array" : [0,1,2,3]
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": "100"
},
)}
}</syntaxhighlight>
 
 
<syntaxhighlight lang="vb">#include "inc/fbJSON.bas"
 
Sub printNodeChildren(Byval n As fbJSON Ptr, Byval level As Integer)
End Sub
 
Dim test As fbJSON Ptr = fbJSON_ImportFile("test1.json")
 
If test = NULL Then
Print "Unable to load json file/string!"
End 1
End If
 
Print fbJSON_ExportString(test, 1)
 
fbJSON_Delete(test)
 
Sleep</syntaxhighlight>
{{out}}
<pre>{
"menu": {
"id" : "file",
"string" : "File:",
"number" : -3,
"boolean1" : true,
"boolean2" : false,
"boolean3" : true,
"sentence" : "the rain in spain falls mainly on the plain. This here " is an escaped quote!",
"null" : null,
"array": [ 0, 1, 2, 3 ]
,
"Thumbnail": {
"Url" : "http://www.example.com/image/481989943",
"Height" : 125,
"Width" : "100"
}
 
}
 
}</pre>
 
=={{header|FunL}}==
Line 2,118 ⟶ 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 3,749 ⟶ 3,833:
<syntaxhighlight lang="raku" line>use JSON::Tiny;
 
my $data =say from-json( '{ "foo": 1, "bar": [10, "apples"] }');
mysay to-json $sample = {%( blue => [1,2], ocean => "water" });
 
</syntaxhighlight>
my $sample = { blue => [1,2], ocean => "water" };
{{out}}
my $json_string = to-json($sample);</syntaxhighlight>
<pre>{bar => [10 apples], foo => 1}
{ "blue" : [ 1, 2 ], "ocean" : "water" }</pre>
 
=={{header|REBOL}}==
Line 3,972 ⟶ 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,589 ⟶ 4,675:
=={{header|Wren}}==
{{libheader|Wren-json}}
<syntaxhighlight lang="ecmascriptwren">import "/json" for JSON
 
var s = "{ \"foo\": 1, \"bar\": [ \"10\", \"apples\"] }"
9,476

edits