Docs - update --collection documentation for json_parse and json_encode commands #175

This commit is contained in:
sagie gur ari 2021-07-10 07:45:18 +00:00
parent c0285d3a0d
commit 48d85f8f73
6 changed files with 20 additions and 10 deletions

View file

@ -1,5 +1,9 @@
## CHANGELOG
### v0.8.4
* Docs - update --collection documentation for json_parse and json_encode commands #175
### v0.8.3 (2021-07-10)
* Fix release with recursive flag to support set data structures as well.

4
Cargo.lock generated
View file

@ -412,9 +412,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "java-properties"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d179c3692142e6fc4080d48d5a4d9c04738a3bece41ff2abdde13d505590c1b7"
checksum = "20e9b11dedd144ceb96484add3f9088c131795e4295ce51448ef755e0ec19c07"
dependencies = [
"encoding",
"lazy_static 1.4.0",

View file

@ -4021,15 +4021,18 @@ writefile, write_text_file
<a name="std__json"></a>
## std::json
The json module provides json parsing and encoding capabilities.<br>
When parsing a JSON string, the structure will be represented by simple variables.<br>
Parsing and encoding JSONs can be do to/from simple variables or to collections (maps/arrays).<br>
By default, when parsing a JSON string, the structure will be represented by simple variables.<br>
The root object (or simple value) will be set in the json_parse output variable and any sub structure will be
defined as variables with prefix of the root variable name.<br>
Object nodes, will have the value of: **[OBJECT]**.<br>
Array nodes will have a length variable defined, for example: **arr.length**<br>
If the --collections flag is provided, parsing will return the JSON value or a handle to a collection which will hold the values (or sub collections).<br>
These collections are better way to handling unknown json structures but must be released with the **release --recursive** command.
Because duckscript variables have no type, the json_encode will define every boolean/numeric value as JSON string.<br>
Below is a simple example showing how to parse and encode values of all types.
Below is a simple example showing how to parse and encode values of all types when using the default behaviour of storing to variables.
```sh
fn test_simple_types
@ -4101,7 +4104,7 @@ end
<a name="std__json__Encode"></a>
## std::json::Encode
```sh
string = json_encode var_name
string = json_encode (--collection handle | var_name)
```
This function will encode all variables, starting from the root variable as a JSON string.<br>
@ -4137,7 +4140,7 @@ json_encode
<a name="std__json__Parse"></a>
## std::json::Parse
```sh
var = json_parse string
var = json_parse [--collection] string
```
This function will parse the provided JSON string and will create variables based on the parsed data.<br>

View file

@ -1,5 +1,5 @@
```sh
string = json_encode var_name
string = json_encode (--collection handle | var_name)
```
This function will encode all variables, starting from the root variable as a JSON string.<br>

View file

@ -1,13 +1,16 @@
The json module provides json parsing and encoding capabilities.<br>
When parsing a JSON string, the structure will be represented by simple variables.<br>
Parsing and encoding JSONs can be do to/from simple variables or to collections (maps/arrays).<br>
By default, when parsing a JSON string, the structure will be represented by simple variables.<br>
The root object (or simple value) will be set in the json_parse output variable and any sub structure will be
defined as variables with prefix of the root variable name.<br>
Object nodes, will have the value of: **[OBJECT]**.<br>
Array nodes will have a length variable defined, for example: **arr.length**<br>
If the --collections flag is provided, parsing will return the JSON value or a handle to a collection which will hold the values (or sub collections).<br>
These collections are better way to handling unknown json structures but must be released with the **release --recursive** command.
Because duckscript variables have no type, the json_encode will define every boolean/numeric value as JSON string.<br>
Below is a simple example showing how to parse and encode values of all types.
Below is a simple example showing how to parse and encode values of all types when using the default behaviour of storing to variables.
```sh
fn test_simple_types

View file

@ -1,5 +1,5 @@
```sh
var = json_parse string
var = json_parse [--collection] string
```
This function will parse the provided JSON string and will create variables based on the parsed data.<br>