Deserializes the specified JSON string into object or array.
JPARSE(json_string, separator_optional)
Replace:
json_string parameter with a JSON format string you need to parse;
separator_optional optional parameter to make function convert string to array by splitting it.
JPARSE('{"name" : "John Smith", "kids": [{"name": "Jim"}, {"name":"Nicky"}]}') will return a proper object.
Let String__c = '["Feb", "Jan", "Dec"]'.
JPARSE({Stub__c.String__c}) returns an array consisting of following elements: 'Feb', 'Jan', 'Dec'.
Let Area__c = 'Plane; Train; Car'.
JPARSE({Stub__c.Area__c}, ';') returns an array consisting of following elements: Plane, Train, Car.
2. JPARSEXML
Deserializes the specified XML string into object.
JPARSEXML(xml_string)
Replace xml_string parameter with a string (in XML format) you need to parse.
JPARSEXML('<person><address>10 South Riverside Plaza</address><age>9</age><names><first>Jon</first><last>Smith</last></names></person>') returns an object person={address=10 South Riverside Plaza, age=9, names={first=Jon, last=Smith}}.
3. JOBJECT
Builds an object from provided key names and values.
JOBJECT(key1, value1, key2, value2, ...)
Replace:
key1, key2 parameters with strings that are key names
value1, value2 parameters with strings that are key values
If omit some value, it will be stored as null.
JOBJECT() will return an empty object {}.
JOBJECT(key1, value1, key2, value2) will return an object {βkey1β:βvalue1β, βkey2β:βvalue2β}
JOBJECT(key1, value1, key2) will return an object {βkey1β:βvalue1β, βkey2β:null}
JGET(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza", "kids": ["Andrew","Jane", "Peter"]}'), JPARSE('["kids", 2]')) will return 'Peter' as "kids" list has element with index 2.
6. JPUT
Puts a value into JSON content using a path provided.
JPUT(json_object, path, value)
Replace:
json_object parameter with an object you want to use;
path parameter with the path to find a field in the object to update;
value parameter with the value a field will be updated with.
You can also pass index as a path if you operate with an array.
If value needs to be added as a last element of an array pass -1 as a path.
JPUT(JPARSE('{"name" : "Jon Smith"}'), 'address', '10 South Riverside Plaza') will add Jon's address property and value to JSON object.
JPUT(JPARSE('["Z", "Y", "X"]'), 0, 'A') returns an array with following elements: A, Y, X.
7. JREMOVE
Removes a field from JSON content using a path provided.
JREMOVE(json_object, key_or_jsonobject)
Replace:
json_object parameter with an object you want to use;
key_or_jsonobject parameter with the key to find a field you need to remove or with array element to be removed from JSON array.
If you need to remove multiple values from object you can pass array of object keys as a key_or_jsonobject
Same is true for JSON arrays: if you need to remove several elements from JSON array pass an array of elements to be removed.
JREMOVE(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza", "age" : 9}'), 'address') removes an address field from the JSON content.
JREMOVE(JPARSE('["Z", "Y", "X"]'), 'X') returns an array with following elements: Z, Y.
JREMOVE(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza", "age" : 9}'), SPLIT('name,age', ',')) returna a JSON object with address property only.
JREMOVE(JPARSE('["1a", "2b", "3c", "4d"]'), SPLIT('1a,2b', ',')) returns an array with following elements: 3c, 4d.
8. JCLEAR
Clears a whole JSON object or nested object using a path provided.
JCLEAR(json_object, key_or_jsonobject_optional)
Replace:
json_object parameter with an object you want to use;
key_or_jsonobject_optional optional parameter with the key to find a field you need to remove or with path to nested object as array of elements.
Both
JCLEAR(JPARSE('{"personnames":{"first":"Jon","last":{"a":"Smith","b":"Ryan"}}, "address": "10 South Riverside Plaza", "age" : 9}'))
and
JCLEAR(JPARSE('{"personnames":{"first":"Jon","last":{"a":"Smith","b":"eee"}}, "address": "10 South Riverside Plaza", "age" : 9}'),null)
will return an empty object {}.
JCLEAR(JPARSE('{"personnames":{"first":"Jon","last":{"a":"Smith","b":"Ryan"}}, "address": "10 South Riverside Plaza", "age" : 9}'),'personnames') returns an initial object where nested object 'personnames' will be empty: {address=10 South Riverside Plaza, age=9, personnames={}}
JCLEAR(JPARSE('{"personnames":{"first":"Jon","last":{"a":"Smith","b":"Ryan"}}, "address": "10 South Riverside Plaza", "age" : 9}'),JPARSE('["personnames","last"]')) returns an initial object where 2nd-level nested object 'last' will be empty: {address=10 South Riverside Plaza, age=9, personnames={first=Jon, last={}}}
9. JSIZE
Returns a number of elements in JSON content.
JSIZE(json_object)
Replace json_object parameter with an object or array you want to get size of.
JSIZE(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza"}')) returns 2 as a number of key-value pairs in JSON content provided.
json_object parameter with an object you want to use ;
path parameter with the path to find a field you need to check (or index if you work with JSON array).
JEXIST(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza"}'), 'Jon Smith') returns true as Jon Smith node is present in JSON content.
JEXIST(JPARSE('["one" , "two", "three", "four"]'), 2) returns true as element with index 2 is present in list.
JEXIST(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza", "appearance": {"eyes":"blue", "hair":"dark"}}'), JPARSE('["appearance", "hair"]')) returns true as "appearance" object has key "hair".
JEXIST(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza", "kids": ["Andrew","Jane", "Peter"]}'), JPARSE('["kids", 2]')) returns true as "kids" list has element with index 2.
11. JMERGE
Merges 2 JSON objects into one.
JMERGE(json_object, json_object)
Replace both json_object parameters with objects you want to merge.
JMERGE(JPARSE('{"name" : "Jon Smith", "address": "10 South Riverside Plaza"}'), JPARSE('{"appearance": {"eyes":"blue", "hair":"dark"}}')) will return object {address=10 South Riverside Plaza, appearance={eyes=blue, hair=dark}, name=Jon Smith}.
12. JEACH
Executes specified function for each element of the list.
json_obect parameter with an object you want to use;
key_function parameter with expression to be executed for each key of the object;
value_function with expression to be executed for each value of the object.
If you don't need to trigger function execution for object keys pass {$JEachKey} as a key_function parameter, if no function needs to be run for object values - pass {$JEach} as value_function parameter.
You can get current element by using the merge field "{$JEach}" and you can get current element index by using the merge field "{$JEachIndex}".
JEACHMAP(JPARSE({$Environment}), {$JEachKey}, IF(INSTANCEOF({$JEach}, Decimal), MULT({$JEach}, 2), {$JEach})) doubles all numeric values of the $Environment context object.
JEACHMAP(JPARSE({$Environment}), IF({$JEach} = true, UPPER({$JEachKey}), {$JEachKey}), {$JEach}) converts to uppercase only those object keys which values are equal to true.