Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard] A new variable type for JSON values and other JSON improvements #382

Closed
9 tasks done
mvladic opened this issue May 23, 2024 · 1 comment
Closed
9 tasks done
Assignees
Milestone

Comments

@mvladic
Copy link
Contributor

mvladic commented May 23, 2024

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`...` or JSON`...` (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.
    image
  • Array.length, Array.append, Array.insert and Array.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
}`
@mvladic mvladic added this to the M20 milestone May 23, 2024
@mvladic mvladic self-assigned this May 23, 2024
mvladic added a commit that referenced this issue May 23, 2024
@mvladic mvladic changed the title [Dashboard] A new variable type for JSON values and other improvements [Dashboard] A new variable type for JSON values and other JSON improvements May 23, 2024
mvladic added a commit that referenced this issue May 24, 2024
mvladic added a commit that referenced this issue May 25, 2024
@prasimix
Copy link
Member

prasimix commented Jun 7, 2024

Fixed

@prasimix prasimix closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants