on 05-27-2021 3:13 PM
Hello,
I have the following challenge:
I have a JSON file stored in the memory with the name "API_result". The stucture looks something like this:
"memory": {
"API_result": [
{
"value A": "aaaaa",
"componentId": "000000000019981475",
"value B": "bbbbb",
"value C": "CCCCC"
}
{
"value A": "aaaaa",
"componentId": "000000000003136619",
"value B": "bbbbb",
"value C": "CCCCC"
}
{
"value A": "aaaaa",
"componentId": "000000000003121415",
"value B": "bbbbb",
"value C": "CCCCC"
}
]
}
I want to store the values of component ID in a separate memory (memory.instrument) as JSON, something like this:
"memory": {
"instrument": [
{
"c_Id": "000000000019981475",
}
{
"c_Id": "000000000003136619",
}
{
"c_Id": "000000000003121415",
}
]
}
To do this, I used the action "update memory" -> "set memory" with the option "Use scripting to build my JSON" enabled. I use following code (based on the documentation)
{{#eachJoin memory.API_result}}
{
"c_ID": {{componentId}}
}
{{/eachJoin}}
This code causes a warning and those not store anything in memory.instrument.
{
"level": "warning",
"code": "W_EXECUTE_ACTION",
"data": {
"type": "edit_memory",
"value": {
"invalid_json": " {\r\n \r\n \"c_ID\": 000000000019981475\r\n \r\n }\r\n, {\r\n \r\n \"c_ID\": 000000000003136619\r\n \r\n }\r\n, {\r\n \r\n \"c_ID\": 000000000003121415\r\n \r\n }\r\n,
"scripting_enabled": true
},
"message": "No valid JSON value for field instrument"
I tried some other variations but had no luck. Any hint is highly welcome.
I was able to do it but you have to put array code outside. Also, assuming you want it to continue to be a string, you have to put quotes around the component ID.
[
{{#eachJoin memory.API_result}}
{
"c_ID": "{{componentId}}"
}
{{/eachJoin}}
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.