I've found some a few resources which has basics of generating a JSON file using JsonObject in AL.
One helpful link is :
https://community.dynamics.com/business/f/dynamics-365-business-central-forum/289143/creating-json-data-in-al-jsonobjectclass
However I'm not sure on how to generate nested objects.
Example would be:
{
"order": {
"orderSessionId": "uf3343d98weicsc445dd4",
"orderId": "O0123456",
"createdAt": "2018-07-11T17:54:31-05:00",
"currency": "GNP",
"orderChannel": "WEB",
"receivedBy": "John Doe",
"totalPrice": 72.99
}
}
I'm can generate the objects i.e. orderSessionID, orderID etc using JsonObject.Add('orderSessionID', 'value') but not sure how to nest it within order object.
Can anyone please assist?
Answers
You can use this:
Regards
So something like
Thanks! I've used a slightly different method but yours is definitely cleaner
1) Passing Null value : How is this done? creates string value of "null" in the JSON
2) Formatting : I've tried to remove decimals using code below however the JSON output converts the value to string. How can I remove the decimal whilst retaining the number property?
You can add a new var like this
And use it like this:
Regards
Regarding the decimals I think I haven't described it clearly.
As an example the code below gives a value of 1,234.0 (numeric) in the JSON output.
How do I format it so that it returns 1234 (numeric) in the JSON output?
I've tried the below but the output in JSON is string, enclosed in double quotes.
In that case you need to do this:
I use two more vars to show what happen, in my case due to regional settings, the decimal point is a comma and in "totalPrice" I need to change after the format so the jsValue.ReadFrom get the correct value.
In the same way you need to get rid of any thousands separator in both cases.
Regards.