The jsonParse helper parses a valid JSON string and returns the resulting object or array. Use it in text-based fields such as relative URI templates and mapper expressions where JSON strings are not automatically deserialized and need to be accessed as objects.
Note: Use triple braces ({{{ }}}) with this helper to prevent Celigo from encoding the output. Verify that the AFE field you are targeting supports objects and object arrays before using jsonParse.
Syntax
{{{jsonParse string}}}
string -- A valid JSON string to parse. Required. Keys must be in double quotes and the string must be properly escaped.
When to use jsonParse
In integrator.io, stringified JSON in standard data fields auto-deserializes -- jsonParse is not needed there. Use jsonParse in these specific contexts:
- Relative URI templates -- to extract primitives from a stringified JSON field for use in a URL path or query parameter.
- Mapper expressions -- to access properties or iterate over a stringified JSON payload that hasn't been deserialized automatically.
Examples
Parse a JSON string into an object
{{{jsonParse record.string}}}
Input:
{
"record": {
"string": "{\"foo\": \"bar\"}"
}
}
Output: { "foo": "bar" }
Extract a value from a stringified JSON field for use in a URI
/api/v2/users.json?page[size]?shardid={{#with (jsonParse record.payload)}}{{shardid}}{{/with}}
Input:
{ "record": { "payload": "{\"shardid\":\"dddt22\"}" } }
Output: /api/v2/users.json?page[size]?shardid=dddt22
Wrap jsonParse in a #with block to access individual properties of the parsed object.
Extract a nested object from a stringified payload
{{#with (jsonParse record.payload)}}{{{jsonStringify event}}}{{/with}}
Input:
{
"record": {
"payload": "{\"event\":{\"type\":\"create\",\"source\":\"api\"},\"id\":[123,456,789],\"status\":\"success\"}"
}
}
Output: {"type":"create","source":"api"}
#with shifts the context to the parsed object, then jsonStringify serializes the event child object back to a JSON string.
Iterate over a stringified JSON array
{{#each (jsonParse record.roles)}}
{{@index}}: {{this}}
{{/each}}
Input:
{ "record": { "roles": "[\"system\",\"admin\",\"editor\",\"contributor\",\"viewer\",\"vendor\"]" } }
Output:
0: system 1: admin 2: editor 3: contributor 4: viewer 5: vendor
Wrap jsonParse in a #each block to iterate directly over a stringified JSON array.
Usage notes
- Always use triple braces (
{{{ }}}). Double braces will encode the output. - The input must be valid JSON: keys in double quotes, values properly escaped.
- In most standard data fields, stringified JSON auto-deserializes --
jsonParseis typically only needed in relative URI templates and mapper expressions. - Use
#with (jsonParse...)to access properties of the parsed object, and#each (jsonParse...)to iterate over a parsed array.