The JSON (JavaScript Object Notation) Format Editor allows you to convert a data bus data stream into JSON format and is available in the following operators in the GRAVITY system:
You build the JSON format by dragging and dropping elements from the Busbar area to the JSON nodes area. To insert a new element, drag a data bus bit from the Busbar area, and drop it where you want it to appear in the structure you are building. To remove an element from the structure, drag it back to the Busbar area. You can also use the navigation buttons for this purpose.
You can also create object arrays, simple arrays, and child objects by dragging an element from the CONTAINER NODE area onto the JSON node area (drag and drop action) in the location where you want it to be added.
You can choose between a simple array and an array of objects by selecting the array node and changing the Array element option in its properties to Simple Value.
By default, the JSON structure is based on the []data array. To return an object instead of an array, remove []data and add
{}object as the main element.
You can also change the node type by selecting the node and modifying the Container type property.
{}object as the main element, the data generated by the operator will include only the last record from the data bus.By default, the element name is the same as the name of the bus bit. You can modify it by clicking the element and changing its name in the Element properties.
If the bit corresponding to a given value on the bus is null, you can omit the elements of the created object or the values of a simple array. To do this, set the Null visibility property to Skip null.
- if the node is a simple array – its value will be an empty array
[]. - if the node is an object – its value will be an empty object
{}. - if the node is an array of objects – any objects whose fields all have
nullvalues will be skipped when creating the array.
If you want all child elements of a given row to be set to Skip null or Show null, use the Set null visibility for elements option on the selected node.
If you want to generate a simple array of values in a node that represents an array, use the Array element option set to Simple value. This option requires that the node have only one child element — a single bus bit (node).
Example:
...
"projectsId": [3,34,54,67]
...When using the editor in the CONVERT BITS TO FORMAT operator, you will have an additional option called Form of root. This option lets you decide whether the JSON format generated by the operator will take the form of a complete object or only the values of the first-level array.
Example:
Full object
{
"data" : [
{
"id": 1,
"name": "name1"
},
{
"id": 2,
"name": "name2"
}
]
}Only array without name
[
{
"id": 1,
"name": "name1"
},
{
"id": 2,
"name": "name2"
}
]