[REST] Consume list of object where key is dynamic

[REST] Consume list of object where key is dynamic

  
Hi,

I want to consume a REST-service with the following JSON

"measures": {
        "02:00:00:00:5b:be": 
	{
	 "res": {"1382003013": [19.6,70]},
         "type": ["temperature","humidity"]
        },
        "70:ee:50:00:58:82": 
	{
          "res": {"1382003056": [1021.9]},
           "type": ["pressure"]
        } 
      } 
as you can see. the "02:00:00:00:5b:be" is the key. is this possible with Outsystems, or should I fall back to ardoJSON/HTTP? so I can parse the raw JSON?
You can parse the raw JSON by specifying an OnAfterResponse, iirc. That'll still mean some work, but it's better than raw HTTP.
Hi J,


Usually he recommendation we give on those scenarios is to transform the dynamic object in an array on OnAfterResponse with a regex .....but in your case with inner objects it's tricky to just to a regex.

Check the attached espace as example of the Regex search/replaces necessary for your example.
Note: my regex are sensible to the number of "{" inside the measure element... it's made specific for the example you posted.

Try it out online here: https://my.outsystemscloud.com/Demos/HomePage.aspx

It transforms each   "02:00:00:00:5b:be": {....}  pair into a  { "key" : "02:00:00:00:5b:be", "value" : { .... }



Note 2: tested in my personal only (C#) the first regex uses a lookbehind that is not "zero-length" ..and I'm not sure if Java supports it. Tell me if you are in java and I'll upload a version without that lookbehind (but needs an extra Regex_Replace ...)

Regards,
João Rosado
I'm in c# so that's fine :)

Hello,

I noticed this use-case and added this functionality to ardoJSON.

No need for weird and very specific regular expressions which may not work if the format is slightly different.

JSON_Lisfity will take up any object in a path and convert it into a list of key/value pairs. For example, your JSON would have become:

"measures": [
	{
           "key": "02:00:00:00:5b:be",
           "value": {
	       "res": {"1382003013": [19.6,70]},
               "type": ["temperature","humidity"]
           }
	},
	{
           "key": "70:ee:50:00:58:82",
           "value": {
               "res": {"1382003056": [1021.9]},
               "type": ["pressure"]
           }
      }
]
awesomesauce.
will check it out later!