Getting Started

Based on its syntax and name, JSON is made for Jave Script. It is, however, widely spread with ports to almost all modern languages like python, R, cpp, or julia.

The JSON format

The JSON format is interconvertible to XML and YML. While XML is mostly only for legacy use, most user input is done using YML. However, behind the scenes there is mostly a conversion from YML to JSON. If you communicate with a machine, you will most likely get data in the JSON format and therefore have to learn to talk in JSON yourself.

We start with a simple JSON string that is generated from a call to a typical JSON API:

{
   "userId": 1,
   "id": 1,
   "title": "delectus aut autem",
   "completed": false
}

In typical XML format, the structural elements are duplicated due to the XML closing tags. Besides not being convenient, this also produces longer strings and therefore uses an increased amount of bandwith.

<?xml version="1.0" encoding="UTF-8" ?>
<root>
  <userId>1</userId>
  <id>1</id>
  <title>delectus aut autem</title>
  <completed>false</completed>
</root>

YML files, on the other hand, are widely used when human input is required. Their structural information does not depend on brackets or commas as separators but rather on line breaks as separators and indentations for the structure. This format is used in settings files.

userId: 1
id: 1
title: 'delectus aut autem'
completed: false

Even though this might look simple, it is not easily compacted as it depends on these indentations. Let’s take the same JSON string from above again and display it compacted:

{"userId":1,"id":1,"title":"delectus aut autem","completed":false}

This string can be easily exchanged between machines and has low overhead. It is typically parsed with a SAX-like algorithm which caches only the necessary parts of this string so we can extract specific information from it.

We now show how the interaction with JSON strings is done in Igor Pro.

JSON in Igor Pro

The following lines are executed from the command line interface (CLI) of Igor Pro. First we will have to input a JSON string to Igor Pro and then we will filter it for a specific property:

JSONXOP_Parse("{\"userId\":1,\"id\":1,\"title\":\"delectus aut autem\",\"completed\":false}")
Variable jsonFromString = V_Value

JSONXOP_GetValue/T jsonFromString, "/title"
print S_Value
   delectus aut autem

We can also directly fetch the same JSON string from a web API:

JSONXOP_Parse(FetchURL("https://jsonplaceholder.typicode.com/todos/1"))
Variable jsonFromUrl = V_Value
JSONXOP_Dump jsonFromUrl
print S_Value
   {
   "completed": false,
   "id": 1,
   "title": "delectus aut autem",
   "userId": 1
   }

All JSON strings are kept in memory until Igor Pro exits and can be referred to by their ID. If you fetch large datasets, it is a good practice to release these JSON objects from memory after using them:

JSONXOP_Release jsonFromString
JSONXOP_Release jsonFromUrl

Operations and Functions

The XOP contains Operations which represent all basic handling of JSON strings. They are all located in the JSONXOP_ namespace and are part of the XOP. There are also Functions that are convenient wrappers to the core operations and reside in the JSON_ namespace. The functions are located in the procedures folder and are the recommended entry point for the XOP.

For a more detailed introduction, take a look at the Operations documentation or use the Search Page functionality for finding a specific entity.