Hi
I want to convert this json to strcuture and problems with this is I'm getting list of elements and values on each row for nodes.
"[{\"UnplannedDown\":[{\"reasons\":[{\"count\":\"3.04\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\"},{\"count\":\"4.32\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\"}],\"percentage\":[{\"count\":\"7.36\"}]}]},
{\"PlannedDown\":[{\"reasons\":[{\"count\":\"0.76\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\"},{\"count\":\"0.76\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\"}],\"percentage\":[{\"count\":\"1.52\"}]}]},{\"Running\":[{\"reasons\":[{\"count\":\"87.32\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\"}],\"percentage\":[{\"count\":\"87.32\"}]}]},
{\"UnplannedIdling\":[{\"reasons\":[{\"count\":\"0\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\"}],\"percentage\":[{\"count\":\"0\"}]}]},
{\"PlannedIdling\":[{\"reasons\":[{\"count\":\"3.79\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\"},{\"count\":\"0.01\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\"}],\"percentage\":[{\"count\":\"3.8\"}]}]}]"
What is the best way I can convert this to struture?
Also I need it from json deserilizer
Hello Suraj,
If you have the JSON file defined Outsystems allows you to directly convert it to a structure
Just copy/paste the text and you should be fine.
Make sure that the JSON is valid of course. You can use this tool to do that.
Hope it helps!
Paulo Rosário
Hi Paulo
Thanks for reply.
Actually, I already have done that but when I pass that structure, I'm not getting any values.
Not sure why it is returning empty.
Hi Suraj,
I just created a test app (see attachment), and the data you supplied seems to work fine:
So your problem must lie elsewhere.
Hi sir
Thanks for taking time to develop.
But why am I getting output like this?
That's a good question. Did you compare my test app with your code? Any differences? Or are you receiving the JSON data from somewhere, and is the structure different (as you can see I use hardcoded values)?
This output is from the test app you have provided which I installed on my PE. I'm receiving JSON data from rest api. There's no difference between your code and my code.
In that case, check the JSON that is sent via the API (by adjusting the logging levels of the REST API in Service Center), and manually check whether there's a difference in thhe JSON with the JSON you based the structure on.
My whole rest api output is this.
[{"cursor":0,"apiName":"event_g.machineAvailabilityInsights","pageSize":0,"resultSet":[{"thingId":283,"thingName":"ABB Robot Tender","insights":"[{\"UnplannedDown\":[{\"reasons\":[{\"count\":\"3.04\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\",\"category\":\"UnplannedDown\"},{\"count\":\"4.32\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\",\"category\":\"UnplannedDown\"}],\"percentage\":[{\"count\":\"7.36\"}]}]},{\"PlannedDown\":[{\"reasons\":[{\"count\":\"0.76\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\",\"category\":\"PlannedDown\"},{\"count\":\"0.76\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\",\"category\":\"PlannedDown\"}],\"percentage\":[{\"count\":\"1.52\"}]}]},{\"Running\":[{\"reasons\":[{\"count\":\"87.32\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\",\"category\":\"Running\"}],\"percentage\":[{\"count\":\"87.32\"}]}]},{\"UnplannedIdling\":[{\"reasons\":[{\"count\":\"0\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\",\"category\":\"UnplannedIdling\"}],\"percentage\":[{\"count\":\"0\"}]}]},{\"PlannedIdling\":[{\"reasons\":[{\"count\":\"3.79\",\"description\":\"RC_LACKOIL\",\"reasonCode\":\"RC_LACKOIL\",\"category\":\"PlannedIdling\"},{\"count\":\"0.01\",\"description\":\"No reason provided\",\"reasonCode\":\"NA\",\"category\":\"PlannedIdling\"}],\"percentage\":[{\"count\":\"3.8\"}]}]}]"}]}]
Out of this, I want output in structure format for insights node.
Yeah, so need a structure that encompasses all of this, right? So create that structure (or use the JSON to Structure), and it should work right? I mean, it's not going to work with the structure from my test app since it's missing a level or two, but just add that and it should work.
Hi @Suraj Borade,
I tried to check your JSON and test it with Outsystems as you can see from the below screenshot, it's working fine
You just have to select the Data Type of JSONDeserialize as a List of your Structure because your JSON stats with [] which denotes an array here and can only be held by a list of structure.
I hope this solves your issue.
Thanks & Regards
Nitish Kumar
Though this is true, this can't be the problem he's having: if you use the structure, instead of a list of structures, as datatype, you get a runtime error, not just an empty list (ask me how I know 😂).
Hi Nitish,
Can you please paste your oml here?
Please find the OML attached.
@Kilian Hekhuis, I also tried not taking this structure as a list and it didn't give me any error, but only give me the empty structure as it was happing with Suraj.
Mmm, really? Did you try in a Reactive or Traditional Web? I used TW, but maybe Reactive behaves diferently?
@Kilian Hekhuis it was Reactive.
Thanks, good to know it works differently there.
Hi guys,
Thanks for taking time.
I should have made it clear that I'm working in Reactive Web Applications.
I am using list as done by @Nitish Kumar
But my question is that I'm getting 5 different list elements in the output as shown here.
My question is can't I have all values at [0] index itself?
Thanks
Hi @Suraj Borade ,
Yes, you can access the [0] of the structure if you want.
Sending you the updated Module with it.