Tools for JSON Comments and JSON Lines


Altova XMLSpy and MapForce JSON tools have long supported JSON and JSON5 for editing and data mapping. As new JSON formats arise in response to real-world usage, the support in these tools is expanding.

This article will help explain the advantages of two newer formats –  JSON with Comments and JSON Lines – and show how to use them in XMLSpy and MapForce.

Tools for JSON Comments and JSON Lines

How to add comments to JSON

Though JSON was created as a pure data interchange format, over time its flexibility and ease of implementation have led to it being used in a variety of different scenarios, for example, in configuration files.  A drawback to JSON in these implementations, however, is that the format doesn’t support comments, making it very difficult to provide needed documentation and annotations in the code.  

JSON5, a superset of JSON, was introduced to address some of the limitations of JSON and indeed allows comments. However, applications based on previous versions of JSON still need a comments mechanism. 

To that end, the JSON with Comments (JSONC) format has been introduced to allow for processing of JSON files that include comments. With JSONC, you can include block and single line comments to describe the functionality of your JSON code without causing processing errors.

In addition to support for JSON and JSON5, the XMLSpy JSON editor provides full validation and editing support for JSON with Comments, recognized via the .jsonc file extension.  As shown below, single line comments are prefixed by // and multiline or block comments are delimited by /* and */ .

JSON with Comments (JSONC)

What is JSON Lines?

Also called newline-delimited JSON, JSON Lines (JSONL) is a format for storing structured data such that each record is on its own line. Because of this, records can be processed one at a time, making the format convenient for storing or processing data where new line delimiters are important, such as log files.  Here’s an example of a simple JSON Lines (.jsonl) document being edited in XMLSpy:

JSON Lines

JSON Lines is also supported by MapForce for JSON data mapping and conversion. You can define a graphical data mapping project to map JSON Lines to or from any of the other data formats supported by MapForce: XML, databases, CSV, Excel, EDI, and so on.

To convert JSON Lines, simply check the JSON Lines box in the component settings. When JSON Lines is selected for a JSON target component, a new JSON line will be created in the output file for each object in the source file when the mapping runs. 

Convert JSON Lines using MapForce

Likewise, if your data integration project reads data from a JSON Lines source file, executing the mapping will create as many elements in the target as there are JSON lines in the source.

Support for JSON with Comments and JSON Lines in Altova JSON tools is helping customers take advantage of new formats adapted to real-world JSON implementations. You can try both XMLSpy and MapForce with a free trial of the Altova MissionKit suite of JSON and data integration tools.

Tags: , , , , , ,
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *