Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Coming Soon

Examples

Record Set Returned

HTML Comment
hiddentrue
Excerpt
hiddentrue

jsonToItems (JSON, JSON Path, Lenient) Converts a block of JSON data into a recordset which contains the attributes for each node. 

Function: jsonToItems

Function: toJson()

Converts a block of JSON data into a recordset which contains the attributes for each node. an object, such as an array or JSON string, to JSON.

Syntax

jsonToItems(JSON String, JSON Path, LenienttoJson(object)

ArgumentTypeDescription
Object
JSON String

Array

String

JSON string
Object to be converted to
recordset
JSON.

Examples


Code Block
JSON PathString

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.

Lenientboolean

Lenient is a flag which determines whether to parse the JSON String leniently. Defaults to false.

Insert excerpt
JSON NodeJSON Node
nameJSONPathSyntax
nopaneltrue
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 array results can be accessed using normal Array Handling Functions
toJson(getCo)

Returns JSON from a lookup with an array of company objects.

Code Block
{
  "getCo" : [ {
    "CompanyID" : 108,
    "CompanyName" : "Romaguera Inc",
    "Industry" : "Manufacturing"
  }, {
    "CompanyID" : 112,
    "CompanyName" : "Becker and Sons",
    "Industry" : "Manufacturing"
 }, {
    "CompanyID" : 398,
    "CompanyName" : "Larson Inc",
    "Industry" : "Manufacturing"
  } ]
}

Code Block
{
forEach(
    $company, toJson(getCo).getCo, $company.CompanyName : $company
)
}
  • Returns JSON from a Lookup
  • Loops over the getCo array to generate a property pair of $company.CompanyName mapped to the company object
  • . Accessed original getCo array in that as a property. Looping over that and generating a property pair of $company.CompanyName mapped to the company object. The foreach returns a list of property pairs. Because their in the curly bracket they get composed into the JSON object 
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"
  }
}

Return JSON from Lookup

Creates a key/value pair of the CompanyName mapped to CompanyID

Code Block
{
forEach(
    $company, toJson(getCo).getCo, $company.CompanyName : $company.CompanyID
)
}

Returns 

Code Block
{
  "Romaguera Inc" : 108,
  "Becker and Sons" : 112,
  "Larson Inc" : 398
}

Return JSON from Lookup

Creates a key/value pair of the CompanyName mapped to CompanyID

Code Block
{
forEach(
    $company, toJson(getCo).getCo, $company.CompanyName : {$company,"CompanyName":toUpper($company.CompanyName)}
)
}

Returns 

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"
  }
}