Error Deserializing JSON Response

Hi, I'm consuming a WS which; at the botton has some "dictionary" on then form

{
"dictionaries": {
"currencies": {
"USD": "US DOLLAR"
},
"aircraft": {
"717": "BOEING 717",
"738": "BOEING 737-800"
},
"locations": {
"DFW": {
"subType": "AIRPORT",
"detailedName": "DALLAS FT WORTH INTL"
},
"ATL": {
"subType": "AIRPORT",
"detailedName": "HARTSFIELD-JACKSON INT"
}
}
}
}


this data is dynamic, sometimes is USD, sometimes ir EUR, sometimes is 717, and sometimes 718 and so on.

How can i parse this JSON without using an Advance onAfterResponse over the WS ??


Regards.

Hi Roberto,


You can use the ardoJSON extension from the forge. It has a method to convert the "dictionary" attributes into a list of key/value structures.


Regards,

João Rosado

Hi Roberto Demestri,

I reviewed your JSON .Since your JSON is created dynamically( as you mentioned ). Means you don't have any fixed column . We cannot convert your json to list as Outsystems required fixed structure to work on. Please find the screen shot for more information.

This is what I have witnessed till now .If you find any method where your can perform the same operation using dynamic json data , please do let me know.

JSON Formatter  :- https://jsonformatter.curiousconcept.com/

Happy Coding :)

Solution

Like I said on my reply there is an action in ardoJSON to do it.


You use it in your OnAfterResponse callback and it can transform the RequestText to replace all the "Dictionary" attributes with lists of name/value pairs.


If you need to replace multiple attributes you may need to call the method multiple times (one for each attribute) 

In your case Path argument should be something like "dictionaries.currencies", "dictionaries.locations", ...


I sugest creating a page where you pass an example of your text, do all the replacements and display the result.

Then use the result text as an example in the REST API window and let Service Studio create all the structures for you. Then add the OnAfterResponse method with the same transformations you did on the test page.


Regards,
João Rosado

Solution

João Rosado wrote:

Like I said on my reply there is an action in ardoJSON to do it.


You use it in your OnAfterResponse callback and it can transform the RequestText to replace all the "Dictionary" attributes with lists of name/value pairs. Then you just need to 

If you need to replace multiple attributes you may need to call the method multiple times (one for each attribute) 

In your case Path argument should be something like "dictionaries.currencies", "dictionaries.locations", ...


I sugest creating a page where you pass an example of your text, do all the replacements and display the result.

Then use the result text as an example in the REST API window and let Service Studio create all the structures for you. Then add the OnAfterResponse method with the same transformations you did on the test page.


Regards,
João Rosado


Thanks for the update . I missed that :)

João Rosado wrote:

Hi Roberto,


You can use the ardoJSON extension from the forge. It has a method to convert the "dictionary" attributes into a list of key/value structures.


Regards,

João Rosado


This solution works. Needs to be to done some adjustments on the process.

1. Forget about the structures created by the swagger file or if you copy the response body after a test; and adapt it accordingly to you needs.

2. Create an onAfterResponse method (just the standar one) for the WS where you programatically need to parse the raw text answer received in the http response.

3. With the JSON_Listify action you achive the conversion to the key value structure;of all the parts needed to be parsed.

4. Re-mount your raw answer so it fits your new structure; so the platform can mount them on the structures ready for your OS App to consume.

Regards everybody !!