Tools for JSON Comments and JSON Lines


Altova XMLSpy and MapForce JSON tools have long supported JSON and JSON5 for editing as well as data mapping and conversion. 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 Comments and JSON Lines – and show how to use them in XMLSpy and MapForce.

Tools for JSON Comments and JSON Lines

How to add JSON comments

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 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 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 */ .

How to comment in JSON

What is JSON Lines (JSONL)?

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 line editor: edit JSON new line

JSON Lines is also supported by MapForce for JSON data mapping and conversion. A common requirement is to convert JSON Lines to CSV or even JSON Lines to JSON. That’s all easy in MapForce, where you can define a graphical data mapping project to map JSON Lines to or from any of the other data formats supported by the software: JSON, 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.

JSON Lines Case Study

Here is a longer exploration of converting JSON Lines data by extracting records from a database table and mapping it to a JSON Lines file for output.

JSON Tools – Free Trial

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: , , , , , ,