Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
JSON documents can be created in PhixFlow using the toJson function and the output modified using the following notations.
Curly Brackets { }
Use curly brackets to create an object, e.g.
{ "FirstName" : "John", "LastName" : "Smith", "Age" : 50 }
Colon : and Dot .
- Use a colon to define a key-value pair, e.g.
{ "key" : "value" }
- The key must always evaluate to be a string
- The value must always evaluate to be a string, number, object, array, boolean or null
- Use a dot to access the key and value, e.g.
$foo.key:$foo.value
Example using curly brackets, colon and dot
At @ and Dollar $
- @ can be used to reference the current object
- It allows access to any key-value pairs that have already been set
- Use the syntax
@.^.
to traverse upwards
- $ can be used to reference the outer object of the current object being created
- It will allow access to any key-value pairs that have already been set
Example using @
Code Block | ||
---|---|---|
| ||
{ forEach( $company, toJson(getCo), $company.CompanyName : { $company, // $company is a JSON node, so all the attributes from this node are added to the node we are building. "CompanyName" : toUpper(@.CompanyName) // This Company Name attribute overwrites the one in the $company JSON node } ) } |
Note the use of @ as a shortcut for the current object, which is $company.
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 using $
Code Block | ||
---|---|---|
| ||
{ "Count":2, forEach( $company, toJson(getCo), $.Count : {$company,"CompanyName" : toUpper($company.CompanyName)} ) } |
Note the use of $.Count as a shortcut for the outer object of the current object being created.
Code Block | ||
---|---|---|
| ||
{ "Count" : 2, "2" : { "CompanyID" : 398, "CompanyName" : "LARSON INC", "Industry" : "Manufacturing" } } |