When talking about data exchange between systems, probably the most common ways to represent (serialize) objects are by using JSON and XML.
JSON (JavaScript Object Notation) in particular is the de-facto standard protocol in the REST-ful world. It is a lightweight, text-based data interchange format that is both human-readable and machine-readable. It was derived from JavaScript but is language-independent, making it a popular choice for data exchange between different systems and applications.
YAML (YAML Ain’t Markup Language, originally “Yet Another Markup Language“) is a human-friendly data serialization standard that’s commonly used for configuration files and data exchange. It’s designed to be more readable than JSON and XML, with a focus on being human-readable and human-writable.
YAML and JSON are both data serialization formats.
While both JSON and YAML are used for data representation, they have some key differences. JSON is a more rigid format ideal for data interchange, while YAML is more human-readable and better suited for configuration files.
YAML has some advantages compared to JSON for some scenarios:
In some scenarios, a JSON to YAML conversion (or vice versa) enables compatibility between systems or tools that prefer one format over the other, promoting a seamless data exchange.
To start supporting this interoperability, in the latest AL language extension 14.3 the JsonObject AL object now has two new methods:
Here is an example of usage. Imagine to have a JSON representation of an object and I need to create a YAML representation of the same object:
For this example, I’m loading (using an InStream) the following JSON file in AL:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
}
]
}
and here is the generated YAML representation of the object:
firstName: John
lastName: Smith
isAlive: true
age: 25
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021-3100
phoneNumbers:
- type: home
number: 212 555-1234
The same works in the opposite way.
Imagine that I neet to import in Dynamics 365 Business Central the following YAML file, containing the definition of a pipeline for a .NET application (this is just a YAML object):
To read the YAML file and convert it to JSON, you can use the following AL code:
and here is the JSON object created from the YAML definition:
This is a quite hidden addition that can help you on working with these protocols.
Original Post https://demiliani.com/2025/03/10/dynamics-365-business-central-yaml-to-json-and-json-to-yaml-conversion/