Kato Integrations Logo Light
Home  /  Resources  /  Blog  /  Now in RPG API Express 3.4 – Enhanced JSON Support!

Now in RPG API Express 3.4 – Enhanced JSON Support!

As technologies and software develop, new data standards are adopted, with JSON being the newest one. After Kato Integration’s release of RPG API Express version 3.4.0, we have added numerous features and bugfixes, enhancing RPG API Express’s parsing and composition APIs. Because of these changes, we’re updating some of our most perennial content.

We’re constantly working to roll out new products and features and we’ve got big news for RPG API Express version 3.3 – it includes enhanced JSON support! With our updated APIs, you can compose, transmit, and parse JSON data using RPG on your IBM i.

What is JSON?

The acronym JSON (pronounced JAY-son) stands for JavaScript Object Notation. Don’t worry – it doesn’t actually require experience with JavaScript (a common scripting language used in internet applications) to read or use JSON data. JSON is a simple data interchange format that is easy to read and approachable for even novice developers. It is widely supported by many common programming languages – for example, PHP, Java, Ruby, and, of course, JavaScript – on multiple platforms.

JSON has a very simple syntax, or code structure, with less markup and overhead than one would see in an XML document. JSON data is stored as key/value pairs, where each data value is paired with a label. Here is an example of a key/value pair:

				
					"Company_Name": "Kato Integrations"
				
			

The same data might be represented in XML like this:

				
					<companyName>Kato Integrations</companyName>
				
			

Note: There is much more to JSON syntax than just simple key/value pairs, but that goes beyond the scope of this article. For a thorough run-down of JSON data types and structures, visit the official JSON website, and see an excellent code example on Wikipedia.

The XML sample looks a lot more like code, doesn’t it? Apart from some extra quotation marks, the JSON sample could be an item in a table or list. That’s why they say JSON is very human-readable! With its more simple syntax, it’s easier to get information from JSON code at a glance without having to read through complex tags and nested elements.

How Does JSON Compare to XML?

JSON and XML fulfill many of the same basic functions – they’re both designed to structure data both for transmission as well as for configuration, and both have support in many programming languages. However, each has their respective strengths and weaknesses. Here are a selection that are particularly applicable to offering and consuming web services:

  • JSON tends to be simpler and more human-readable, but XML offers more flexible ways to traverse a document and extract the data you need.
  • JSON is strongly typed – the syntax denotes the data type of each value. This allows for fewer data conversions before information can be used. In XML, everything is weakly typed – it’s all considered character data. XML must rely on supporting technologies like XSD or even simple documentation to communicate intended data types to the developer who must then handle converting character data into dates, timestamps, or numbers within their code.
  • JSON supports “complex structures” – arrays and objects. Arrays provide the ability to define an ordered collection of values, whereas objects are unordered sets of name/value pairs. These structures allow JSON data to be mapped much more effectively in languages which support object-oriented development. Using XML would require the usage of an XSD or documentation to achieve the same goals.
  • JSON data may only be defined using the Unicode character encoding (UTF-8, UTF-16, or UTF-32) which helps greatly reduce “encoding confusion”, and ensures that all JSON parsers are able to handle all documents equally well. XML relies on UTF-8 as the default, but may also use other character encodings. However, XML parsers are not expected to have support beyond UTF-8 or UTF-16 (and generally ISO-8859-1), so it’s possible to create XML documents in character encodings that another XML parser may not be able to read – or if it can read it, it will need to convert the data before parsing and incur a performance penalty.
  • JSON objects tend to have a smaller data foot print than that of a comparable XML document, which can reduce transmission and processing time. The large size of a XML documents is one of the most common complaints among developers.

The main advantage of XML over JSON is the use of schemas for strict document definitions. While more work is being done to create usable JSON schema validators, there is not yet a widely supported approach, and is it not common to see these in practice. The only validation done by most JSON parsers is to confirm that the presented data is in a valid JSON format. If you require a strictly formatted structure, with ordered or required elements, XML may still be the best way to go.

Where is JSON Used?

JSON has become popular with web services because of its small data footprint and language-independent format. Companies like GoogleTwitter, and Microsoft return JSON data from their web services. Amazon has introduced JSON-based web services for many of their cloud computing solutions, including their Glacier cold data storage and their Machine Learning data processing and pattern recognition service.

You can even use RPG API Express to create your own web service that consumes and/or returns JSON data, in much the same way as you would for XML. This flexible format offers limitless possibilities, and we’re eager to help you explore all that JSON has to offer!

Contact our support team here to explore how RPG API Express can meet your specific JSON communication requirements on IBM i.

Table of Contents