-
-
Notifications
You must be signed in to change notification settings - Fork 166
Description
JSON is alternative to structures in Dashboard projects (for now, JSON is only supported in Dashboard projects!). Structure has fixed set of fields which must be specified during the development time. In the runtime you can't extend a structure value with a new filed name. Contrary to that, JSON values are completely open, you don't need to specify its structure during development and you can build arbitrary JSON values during the runtime. We can say that structures are statically typed and JSON is dynamically typed.
- Add
json
variable type - Support JSON literal in expressions. Syntax is
json`...`
orJSON`...`
(instead of quotes, a backtick character is used), for example:json`{ "a": 1, "b": 2, "c": { "arr": [1, 2, 3] } }`
- Allow ObjectExpression to construct JSON values [1].
- Add
JSON.get
function. For example:Flow.get(json_value, "c.arr.0")
- Add
JSON.clone
function to make a deep clone/copy of the existing JSON object. - JSON members should be possible to be accessed like struct and array members. For example:
json_value.c.arr[0]
- Support assigning value to JSON member using SetVariable action.
-
Array.length
,Array.append
,Array.insert
andArray.remove
support for JSON - JSONParse should output json value by default.
[1] JSON values can be constructed using EEZ Flow Expression by using either JSON literal or ObjectExpression construct. For example, the following expressions will construct the same JSON value:
- by using JSON literal:
json`{ "a": 1 }`
- or by using ObjectExpression:
{ a: 1 }
As you can see, ObjectExpression is simpler because no quotes are required for the property names. Also, in ObjectExpression for the property values you can use other expressions where for the JSON literals you must only use literal values. For example this is allowed:
{
a: int_var
}
wher int_var
is for example local variable.
But, you can't do the same with JSON literal:
// This is not valid expression!!!
json`{
"a": int_var
}`