Search

Home

Home

JSON Format Editor

JSON Format Editor

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:

OUTPUT DATAOUTPUT DATA

OUTPUT FILEOUTPUT FILE

OUTPUT FTPOUTPUT FTP

CONVERT BITS TO FORMATCONVERT BITS TO FORMAT

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.

image

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.

image

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.

icon
Since the elements of a simple array are simple values, the editor can contain only one bit under the node of such an array — this bit will be used to generate the values of that array.
image
icon
The operator generates data based on the nesting levels of the nodes. The data for each level is obtained by grouping the bus data according to the bits used at that nesting level and its parent levels. This is a very important feature, as it allows processing of parent–child type data (for example, an order and its items). A bus carrying “flat” data (where parent data is repeated as many times as there are child records) can thus be interpreted as a hierarchical structure, provided that the corresponding bits are placed at the correct levels.

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.

image

You can also change the node type by selecting the node and modifying the Container type property.

image
icon
If the data bus contains multiple records and you use {}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.

image

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.

image
icon
If all elements of a node have the Null visibility property set to Skip null, then:
  • 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 null values 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.

image

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]
...
image

When using the editor in the CONVERT BITS TO FORMATCONVERT 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.

image

Example:

Full object

{
	"data" : [
		{
			"id": 1,
			"name": "name1"
		},
		{
			"id": 2,
			"name": "name2"
		}		
	]
}

Only array without name

[
		{
			"id": 1,
			"name": "name1"
		},
		{
			"id": 2,
			"name": "name2"
		}		
]