Hello people,
I get a JSON with this structure:
{
"Anna": {
"name" : "Anna W","age": 23
},
"Andrew":{
"name" : "Andres G""age": 32
},..n
}
I transform it in a dictionary, but a I getting problems when I try to iterate it with a foreach, anyone knows another way to do it?
Discussion posts and replies are publicly visible
What problems are you getting when using a!forEach(), and what are you trying to do when transforming the data?
This is the example code,
= load( local!a: a!fromJson(a!toJson({ "Anna": { "name": "Anna W", "age": 23 }, "Andrew": { "name": "Andres G", "age": 32 }} )), a!forEach( items: local!a, expression: fv!item ) )
It recognise the Dictionary with a single item, I can not iterate it, I need to transform it in a regular CDT
Resul:
List of Dictionary: 1 item
Dictionary
Anna: Dictionary
name: "Anna W"
age: 23
Andrew: Dictionary
name: "Andres G"
age: 32
By definition you wouldn't be able to iterate over this, because it's not an array of a single dictionary, but rather a group of different dictionaries ("Anna" and "Andrew" are each separate items in the same parent dictionary, and each include their own unique dictionaries). The fact that both of their dictionaries happen to contain the same data is coincidental and irrelevant to the fact that the structure is not set up to treat them as an array.
thanks for your answer, but I need to convert it in a CDT and I can not change the JSON Structure, Do you Know any way to do that?
Will the sub-dictionaries ("Andrew", "Anna") always have the same names, or will those be completely random? Will these sub-CDTs always have the same fields as each other / as in your example?
The only thing I can really think of is that you could try modifying the JSON string on the local side, in order to remove the sub-CDT parent names, which would mean you end up with an array of the same type of dictionary (presumably) after a!fromJson is run - matching the following data structure basically:
{ { "name": "Anna W", "age": 23 }, { "name": "Andres G", "age": 32 } }
They will be ramdom, and I need to use name age ... etc in a CDT thats my problem
Do you persist this JSON in the Appian MYSQL database, or do you process the response from the external system on the fly?
You will need to modify the JSON-String, then. You could, for example, use a regular expression to remove the name. Alternatively, this might(!) help, with the provision that I have not tested this myself: https://community.appian.com/b/appmarket/posts/dictionary-utilities
Hi, I need to convert it In a CDT in order to compare with anoter JSON, Do you Know if I can access to the list items with the index like "local!a[0]", like a regular languaje?
Did you ever resolve this issue?