IPWorks IoT 2020 Python Edition

Questions / Feedback?

parse Method

This method parses the specified JSON data.


def parse() -> None: ...


This method parses the specified JSON data.

When parsing a document events will fire to provide information about the parsed data. After parse returns the document may be navigated by setting x_path if build_dom is True (default). If build_dom is False parsed data is only accessible through the events.

The following events will fire during parsing:

If build_dom is True (default), x_path may be set after this method returns. x_path may be set to navigate to specific elements within the JSON document. This will be the path to a specified value within the document. Since arrays in JSON only contain values, and no associated object name, an empty name will be used for these values. To reach an array element at position 1, the path must be set to "[1]". In addition, a root element named "json" will be added to each JSON document in the parser.

build_dom must be set to True prior to parsing the document for the x_path functionality to be available.

The x_path property accepts both XPath and JSONPath formats. Please see notes below on both formats.


The path is a series of one or more element accessors separated by '/'. The path can be absolute (starting with '/') or relative to the current x_path location.

The following are possible values for an element accessor:

'name'A particular element name.
[i]The i-th subelement of the current element.
..the parent of the current element.

When x_path is set to a valid path the following properties are updated:

build_dom must be set to True prior to parsing the document for the x_path functionality to be available.

Simple JSON document

  "firstlevel": {
    "one": "value",
    "two": ["first", "second"],
    "three": "value three"
Example (Setting XPath)

Document root JsonControl.XPath = "/"
Specific Element JsonControl.XPath = "/json/firstlevel/one/"
i-th Child JsonControl.XPath = "/json/firstlevel/two/[i]/"

Note: When using XPath notation the root element is always referred to as "json". As in the above examples this means all paths will begin with "/json".


This property implements a subset of the JSONPath notation. This may be set to point to a specific element in the JSON document.

The JSONPath is a series of one or more accessors in either dot-notation

Or bracket-notation

After setting x_path the following properties are populated:


Given the following JSON document:

    "store": {
        "book": [
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
        "bicycle": {
            "color": "red",
            "price": 19.95
The following code shows several examples.

Get the first book's author:

json.XPath = "$.store.book[0].author";

//"Nigel Rees"
Select the first book and inspect the children:

json.XPath = "$.store.book[0]";
Console.WriteLine("Child Count: " + json.XChildren.Count);
Console.WriteLine(json.XChildren[1].Name + ": " + json.XChildren[1].XText);

//Child Count: 4
//author: "Nigel Rees"
Get the price of the second book:

json.XPath = "$['store']['book'][1]['price']";

Get the second to last book's author:

json.XPath = "$['store']['book'][last() - 1]['author']";
Console.WriteLine(json.XPath); //Note that "last() - 1" is resolved to "3".

//"Herman Melville"
Display the full subtree at the current path:

json.XPath = "$.store.book[0]";

//            {
//                "category": "reference",
//                "author": "Nigel Rees",
//                "title": "Sayings of the Century",
//                "price": 8.95
//            }

Input Properties

The class will determine the source of the input based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops.

If parsing multiple documents call reset between documents to reset the parser.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Python Edition - Version 20.0 [Build 8265]