ddangler
8 years agoNew Contributor III
How to create a JSON array that works for all types(String, number)?
Hi Forum,
I need to create a JSON array by capturing values from the previous snap. Basic requirement is as below:
Input:
[
{
"prop1": "abc",
"prop2": "2",
"prop3": null
}
]
Output:
[
{
"custom_fields": [
{
"id": 1,
"value": "abc"
},
{
"id": 2,
"value": 2
},
{
"id" : 3
"value" : null
}
]
}
]
The JSON array should work for all data types(string, null and number). so I created a simple pipeline with mapping logic as :
JSON.parse('[{"id": 1, "value": '+ $prop1 + '}, {"id": 2, "value": ' + $prop2 + '}, { "id" : 3, "value" : '+ $prop3 +' } ]')
But it throws error
Failure: Unable to parse JSON value, Reason: Unrecognized token ‘abc’: was expecting (‘true’, ‘false’ or ‘null’), Resolution: Please check the format of the JSON value
Here is the sample pipeline:
1_2017_08_16.slp (3.5 KB)