JSON: Difference between revisions
Content added Content deleted
Line 1,530: | Line 1,530: | ||
strings, and objects. Nor is there a standardized Forth library to build |
strings, and objects. Nor is there a standardized Forth library to build |
||
and use such structures. But there are many different Forth libraries, |
and use such structures. But there are many different Forth libraries, |
||
written by individuals, available |
written by individuals, available though finding them is not always easy and the syntax and behavior is different for each. |
||
The syntax and behavior is different for each. |
|||
The library code used below can be found here: |
The library code used below can be found here: |
||
https://github.com/DouglasBHoffman/FMS2 |
https://github.com/DouglasBHoffman/FMS2 |
||
Load a JSON string into a data structure. |
Load a JSON Forth string into a data structure. |
||
<pre> |
<pre> |
||
s\" {\"value\":10,\"flag\":false,\"array\":[1,2,3]}" $>json value j |
s\" {\"value\":10,\"flag\":false,\"array\":[1,2,3]}" $>json value j |
||
Line 1,549: | Line 1,548: | ||
Create a new data structure and serialize it into JSON. |
Create a new data structure and serialize it into JSON. |
||
<pre> |
<pre> |
||
j{ "another":"esc\" |
j{ "another":"esc\"ap\u20ACed" }j 1 j :insert j :. |
||
j :. |
|||
</pre> |
</pre> |
||
Prints the modified JSON: |
Prints the modified JSON: |
||
Line 1,556: | Line 1,554: | ||
{ |
{ |
||
"value": 10, |
"value": 10, |
||
"another": "esc" |
"another": "esc"ap€ed", |
||
"flag": false, |
"flag": false, |
||
"array": [ 1, 2, 3] |
"array": [ 1, 2, 3] |
||
Line 1,562: | Line 1,560: | ||
Convert the JSON object into a string. Print the string. |
Convert the JSON object into a string object. Print the string. |
||
<pre> |
<pre> |
||
j json>$ :. |
j json>$ :. |
||
</pre> |
</pre> |
||
{ |
{"value":10,"another":"esc\"ap\u20ACed","flag":false,"array":[1,2,3]} |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |