Please run the following example code.
import ballerina/io;
public function main() {
json j = {"id": 1, "name": "John", "address": {"city": "New York", "country": "USA"}};
io:println(j);
}
Here j is printed in the console without formatting as shown below.
{"id":1,"name":"John","address":{"city":"New York","country":"USA"}}
What is the recommended way to print formatted JSON value?
You can use the
thisarug/prettifypackage to pretty print a JSON value.This code will print the following: