how to serialize json Record and nested List

how to serialize json Record and nested List

  

Hi Gang,


I would like to publish a rest service over json.

How to I format the JSON response if my response consists of a parent and children. 

The serialize json only seems to convert the parent to json if I pass it a structure made up of an object and list.

Thanks in advance




Hi Geoff,

I'm not sure what you are doing there. When you expose a REST service, OutSystems will serialize everything for you, no need to explicitly serialize yourself.

I would like to format as json response like this

{
"ResourceId": "87010101",
"PeriodId": "201550",
"Status": "P",
"DateFrom": "2015-12-07",
"DateTo": "2015-12-13",
"Activity": "B-00",
"Description": "Project  ABW1",
"JobType": "OFF",
"Project": "ABW1",
"Project_description": "?",
"TimeCode": "NORM",
"TimeCode_description": "?",
"WorkOrder": "ABW1-1",
"WorkOrder_description": "?",
"InvValue": "8",
"CostC": "410",
"CostCat": "MS",
"Rate": "0",
"Unit": "H",
"WorkDay": [{
"Day": "2015-12-08",
"HoursWorked": "8"
},
{
"Day": "2015-12-09",
"HoursWorked": "8"
},
{
"Day": "2015-12-10",
"HoursWorked": "8"
}
]
}



the data comes from two tables. One to Many.

You get the data as two querys or one query (join)

How do you format the output as desired. I have not found a way.

Regards

GEORGE



Solution

HI George,


Apart from the part where you don't need JsonSerialize for this (like Killian said), what part of it didn't work? Looking at the screenshots in the first post I would say it would have done what you wanted.

Also if you made the Work variable your output and just removed the Serialize and the Response assign it would give the same expected result.


What part of it isn't working?


Edit: oh, also you don't need to loop over the weekdays, since you could probably just assign the complete list from the query to the structure list attribute (since its just a 1-many relationship).


Regards,
João Rosado

Solution

yep user error.....


original error was the looping over weekdays, and it all went bad after that. The length did not incremented but I had populated the array. Assigning the complete list did it all for me....then i could remove the manual json seralizing which was hit and hope.


Time constraints..i.e. a day to create something cool in Outsystems to get some interest, maybe.

Thanks João  & Kilian

Como usar o json no outsystem.?

Hi daianne caetano,

Can you please post your problem in english? So that someone else out of your country can help.

I translated your question in google and it translated as 

How to use json in the outsystem?

Are you planning to consume some API?

Good morning I need to load the information that is on the screen and give an update to the database using json.