Coming Soon
...
hidden | true |
---|
Excerpt | ||
---|---|---|
| ||
jsonToItems (JSON, JSON Path, Lenient) Converts a block of JSON data into a recordset which contains the attributes for each node. |
Function: jsonToItems()
Converts a block of JSON data into a recordset which contains the attributes for each node.
Syntax
...
Function: toJson()
Converts an object, such as an array or JSON string, to JSON.
Syntax
toJson(object)
Argument | Type | Description |
---|
...
...
Object to be converted to |
...
JSON. |
...
The JSON Path expression is evaluated against the data provided by the JSON String. It determines which elements are extracted from the JSON.
Defaults to “$” which matches the entire document. This must be passed in as a string i.e. encapsulated in quotes.
...
Lenient is a flag which determines whether to parse the JSON String leniently. Defaults to false
.
...
Examples
Record Set Returned
Code Block |
---|
jsonToItems('{"data":[{"value":"foo"},{"status":"bar"}]}', '$.data', true) |
Returns
Code Block |
---|
// returns a record set
{"value" : "foo"}, { "value" : "bar"} |
Array Returned
Code Block |
---|
jsonToItems('{"data":[{"value":"foo"},{"status":"bar"}]}', '$.data', true).value |
Returns
Code Block |
---|
// returns an array of values*
[foo, bar] |
...
The returned JSON has the following syntax:
Objects are enclosed in curly brackets, or braces ( { } )
An object's key-value pairs are separated by a comma ( , )
The key and value in a pair are separated by a colon ( : ), e.g. key : value
Keys in an object are strings, whereas values may be a string, number, object, array, true, false, or null, including another object or an array
- Objects can contain other objects and/or arrays
Arrays are enclosed in square brackets ( [ ] )
An array's values are separated by a comma ( , )
Each value in an array may be of a different type, including another array or an object
- Arrays can contain other arrays and/or objects
Examples
The data being converted:
CompanyID | CompanyName | Industry |
---|---|---|
108 | Romaguera Inc | Manufacturing |
112 | Becker and Sons | Manufacturing |
398 | Larson Inc | Manufacturing |
Example 1
Code Block | ||
---|---|---|
| ||
//Return the data from the lookup connector, getCo, as JSON
toJson(getCo) |
Returns JSON containing an array of objects (each object is contained by curly brackets). Each object contains 3 key-value pairs, where the key and value are separated by a colon ( : ) and each key-value pair is separated by a comma ( , ).
Code Block | ||
---|---|---|
| ||
[ {
"CompanyID" : 108,
"CompanyName" : "Romaguera Inc",
"Industry" : "Manufacturing"
}, {
"CompanyID" : 112,
"CompanyName" : "Becker and Sons",
"Industry" : "Manufacturing"
}, {
"CompanyID" : 398,
"CompanyName" : "Larson Inc",
"Industry" : "Manufacturing"
} ] |
Example 2
Code Block | ||
---|---|---|
| ||
{
//For each $company object, return the data from the lookup connector, getCo, as JSON
forEach(
$company, toJson(getCo),
//Create a key-value pair of the $company object's CompanyName, paired with the $company object
$company.CompanyName : $company
)
} |
Returns JSON containing the $company object's CompanyName, e.g. "Romaguera Inc", paired with the $company object, e.g. { "CompanyID" : 108, "CompanyName" : "Romaguera Inc", "Industry" : "Manufacturing" } as a key-value pair.
Code Block | ||
---|---|---|
| ||
{
"Romaguera Inc" : {
"CompanyID" : 108,
"CompanyName" : "Romaguera Inc",
"Industry" : "Manufacturing"
},
"Becker and Sons" : {
"CompanyID" : 112,
"CompanyName" : "Becker and Sons",
"Industry" : "Manufacturing"
},
"Larson Inc" : {
"CompanyID" : 398,
"CompanyName" : "Larson Inc",
"Industry" : "Manufacturing"
}
} |
...
Example 3
Code Block | ||
---|---|---|
| ||
{
forEach(
//For each $company object, return the data from the lookup connector, getCo, as JSON
$company, toJson(getCo),
//Create a key-value pair of the $company object's CompanyName, paired with the $company object's CompanyID
$company.CompanyName : $company.CompanyID
)
} |
Returns JSON containing a key-value pair of the CompanyName mapped to CompanyID.
Code Block | ||
---|---|---|
| ||
{
"Romaguera Inc" : 108,
"Becker and Sons" : 112,
"Larson Inc" : 398
} |
...
Example 4
Code Block | ||
---|---|---|
| ||
{
forEach(
//For each $company object, return the data from the lookup connector, getCo, as JSON
$company, toJson(getCo),
//Create a key-value pair of the CompanyName paired with the $company object, and convert the CompanyName within the $company object to uppercase
$company.CompanyName : {$company,"CompanyName":toUpper($company.CompanyName)}
)
} |
Returns JSON containing multiple key-value pairs, where the keys are the $company object's CompanyName, and the values are the $company objects. In each $company object, there are 3 key-value pairs, where the value paired with the key, "CompanyName", is converted to uppercase.
Code Block | ||
---|---|---|
| ||
{
"Romaguera Inc" : {
"CompanyID" : 108,
"CompanyName" : "ROMAGUERA INC",
"Industry" : "Manufacturing"
},
"Becker and Sons" : {
"CompanyID" : 112,
"CompanyName" : "BECKER AND SONS",
"Industry" : "Manufacturing"
},
"Larson Inc" : {
"CompanyID" : 398,
"CompanyName" : "LARSON INC",
"Industry" : "Manufacturing"
}
} |
...
Example 5
Code Block | ||
---|---|---|
| ||
do(
//For each $company object, return the data from the lookup connector, getCo, as JSON and prefix the array of $company objects with the string, "CompanyData"
{"CompanyData":
forEach($company, toJson(getCo),
//output the $company object
{$company}
)
}
) |
Returns a key-value pair of the string, "CompanyData" paired with an array of $company objects.
Code Block | ||
---|---|---|
| ||
{
"CompanyData" : [ {
"CompanyID" : 108,
"CompanyName" : "Romaguera Inc",
"Industry" : "Manufacturing"
}, {
"CompanyID" : 112,
"CompanyName" : "Becker and Sons",
"Industry" : "Manufacturing"
}, {
"CompanyID" : 398,
"CompanyName" : "Larson Inc",
"Industry" : "Manufacturing"
} ]
} |