JSON Class

Properties   Methods   Events   Config Settings   Errors  

The JSON class can be used to parse and write JSON documents.

Syntax

class ipworksiot.JSON

Remarks

The JSON class offers a fast and simple way to parse and write information in JSON documents.

Parsing JSON

The JSON class parses JSON documents and verifies that they are well-formed. The results are provided through a set of events.

In addition, the document structure may be queried through an xpath mechanism that supports a subset of the XPath and JSONPath specification.

The parser is optimized for read applications, with a very fast engine that builds internal DOM structures with close to zero heap allocations. Additionally, build_dom can be set to False, which reduces the overhead of creating the DOM and offers a fast forward-only parsing implementation that fires events to provide the parsed data.

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

The following events will fire during parsing:

If build_dom is True (default), xpath may be set after this method returns. xpath may be set to navigate to specific elements within the JSON document. This will be the path to a specified value within the document. Because 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 before parsing the document for the xpath functionality to be available.

The xpath property accepts both XPath and JSONPath formats. Please review the following notes on both formats.

XPath

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 xpath 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 xpath is set to a valid path, the following properties are updated:

build_dom must be set to True before parsing the document for the xpath functionality to be available.

Simple JSON Document

{
  "firstlevel": {
    "one": "value",
    "two": ["first", "second"],
    "three": "value three"
  }
}
Example 1. 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 previous examples, this means all paths will begin with "/json".

JSONPath

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

$.store.book[0].title
or in bracket-notation, as follows:
$['store']['book'][0]['title']

After setting xpath, the following properties are populated:

Example 2. Setting JSONPath:

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"; Console.WriteLine(json.XText); //Output //"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); //Output //Child Count: 4 //author: "Nigel Rees" Get the price of the second book:

json.XPath = "$['store']['book'][1]['price']"; Console.WriteLine(json.XText); //Output //12.99 Get the second to last book's author:

json.XPath = "$['store']['book'][last() - 1]['author']"; Console.WriteLine(json.XText); Console.WriteLine(json.XPath); //Note that "last() - 1" is resolved to "3". //Output //"Herman Melville" //$['store']['book'][3]['author'] Display the full subtree at the current path:

json.XPath = "$.store.book[0]"; Console.WriteLine(json.XSubTree); //Output // { // "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.

Writing JSON

The JSON class also can be used to create a JSON document.

The document is written to the selected output property. In addition, as the document is written, the on_json event will fire. The Text event parameter contains the part of the document currently being written.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

Example. Writing a JSON Document:

Writing a simple JSON document describing a pet: Json json = new Json(); json.OutputFile = "C:\\temp\\fido.json"; json.StartObject(); json.PutProperty("name", "fido", 2); json.PutName("previousOwners"); json.StartArray(); json.PutValue("Steve Widgetson", 2); json.PutValue("Wanda Widgetson", 2); json.PutValue("Randy Cooper", 2); json.PutValue("Linda Glover", 2); json.EndArray(); json.PutProperty("weightUnit", "lbs", 2); json.PutProperty("weight", "62", 3); json.EndObject(); json.Flush();

This example results in the following JSON:

{
  "name": "fido",
  "previousOwners": [
    "Steve Widgetson",
    "Wanda Widgetson",
    "Randy Cooper",
    "Linda Glover"
  ],
  "weightUnit": "lbs",
  "weight": 62
}

When writing multiple documents, call reset between documents to reset the writer.

Modifying JSON

The JSON class also allows for modifying existing JSON documents. After loading a JSON document with parse the document may be edited. The class supports inserting new values, renaming or overwriting existing values, and removing values. After editing is complete, call save to output the updated JSON document.

The following methods are applicable when modifying a JSON document:

When save is called, the modified JSON is written to the specified output location.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

Example 1. Inserting New Values:

To insert new values in a JSON document, first load the existing document with parse. Next set xpath to the sibling or parent of the data to be inserted. Call insert_property or insert_value and pass the ValueType and Position parameters to indicate the type of data being inserted and the position.

The ValueType parameter of these methods specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

The Position parameter of these methods specifies the position of Value. Possible values are as follows:

  • 0 (Before the current element)
  • 1 (After the current element)
  • 2 (The first child of the current element)
  • 3 (The last child of the current element)

For example:

Given the following JSON:

{
    "store": {
        "books": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
            }
        ]    
    }
}

Insert a new property "price" for each book:

json.XPath = "/json/store/books/[1]"; json.InsertProperty("price", "8.95", 3, 3); //3 - Number, 3 - Last Child json.XPath = "/json/store/books/[2]"; json.InsertProperty("price", "12.99", 3, 3); //3 - Number, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "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
    }
    ]
  }
}

To add a new book to the array:

json.XPath = "/json/store/books"; json.InsertValue("", 0, 3); //0 - Object, 3 - Last Child json.XPath = "/json/store/books/[3]"; json.InsertProperty("category", "fiction", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("author", "Herman Melville", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("title", "Moby Dick", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("price", "8.99", 3, 3); //3 - Number, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "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",
      "price": 8.99
    }
    ]
  }
}

To add a new array property to each book:

json.XPath = "/json/store/books/[1]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[1]/tags"; json.InsertValue("quotes", 2, 3); //2 - String, 3 - Last Child json.InsertValue("british", 2, 3); //2 - String, 3 - Last Child json.XPath = "/json/store/books/[2]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[2]/tags"; json.InsertValue("trilogy", 2, 3); //2 - String, 3 - Last Child json.InsertValue("war", 2, 3); //2 - String, 3 - Last Child json.XPath = "/json/store/books/[3]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[3]/tags"; json.InsertValue("classic", 2, 3); //2 - String, 3 - Last Child json.InsertValue("whales", 2, 3); //2 - String, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["quotes", "british"],
      "category": "reference",
      "author": "Nigel Rees",
      "title": "Sayings of the Century",
      "price": 8.95
    },
    {
      "tags": ["trilogy", "war"],
      "category": "fiction",
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "category": "fiction",
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

Example 2. Removing Values:

To remove existing values, set xpath and call the remove method. Continuing with example 1, to remove the first book: json.XPath = "/json/store/books/[1]"; json.Remove(); json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["trilogy", "war"],
      "category": "fiction",
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "category": "fiction",
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

To remove the "category" properties from each book: json.XPath = "/json/store/books/[1]/category"; json.Remove(); json.XPath = "/json/store/books/[2]/category"; json.Remove(); json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["trilogy", "war"],
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

Example 3. Updating Existing Names and Values:

The set_name and set_value methods may be used to modify existing names and values. Continuing with the preceding JSON in example 2, to rename "tags" to "meta" and update values within the array and prices:

//Rename "tags" to "meta" for 1st book json.XPath = "/json/store/books/[1]/tags"; json.SetName("meta"); //Update Price json.XPath = "/json/store/books/[1]/price"; json.SetValue("13.99", 3); //3 - Number //Rename "tags" to "meta" for 2nd book json.XPath = "/json/store/books/[2]/tags"; json.SetName("meta"); //Update tag "whales" to "revenge" json.XPath = "/json/store/books/[2]/meta/[2]"; json.SetValue("revenge", 2); //2 - String //Update Price json.XPath = "/json/store/books/[2]/price"; json.SetValue("9.99", 3); //3 - Number json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "meta": ["trilogy", "war"],
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 13.99
    },
    {
      "meta": ["classic", "revenge"],
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 9.99
    }
    ]
  }
}

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

build_domWhen True, an internal object model of the JSON document is created.
input_dataThis property includes the JSON data to parse.
input_fileThis property specifies the file to process.
output_dataThis property includes the output JSON after processing.
output_fileThis is the path to a local file where the output will be written.
overwriteThis property indicates whether or not the class should overwrite files.
validateThis property controls whether documents are validated during parsing.
xchild_countThe number of records in the XChild arrays.
xchild_element_typeThe ElementType property indicates the data type of the element.
xchild_nameThe Name property provides the name of the element.
xchild_x_textThis property contains the text of the element.
xelementThis property includes the name of the current element.
xelement_typeThis property indicates the data type of the current element.
xerror_pathThis property includes an XPath to check the server response for errors.
xparentThe parent of the current element.
xpathThis property provides a way to point to a specific element in the response.
xsub_treeThis property includes a snapshot of the current element in the document.
xtextThis property includes the text of the current element.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

configSets or retrieves a configuration setting.
end_arrayThis method writes the closing bracket of a JSON array.
end_objectThis method writes the closing brace of a JSON object.
flushThis method flushes the parser's or writer's buffers.
has_xpathThis method determines whether a specific element exists in the document.
insert_propertyThis method inserts the specified name and value at the selected position.
insert_valueThis method inserts the specified value at the selected position.
parseThis method parses the specified JSON data.
put_nameThis method writes the name of a property.
put_propertyThis method writes a property and value.
put_rawThis method writes a raw JSON fragment.
put_valueThis method writes a value of a property.
removeThis method removes the element or value set in XPath.
resetThis method resets the class.
saveThis method saves the modified JSON document.
set_nameThis method sets a new name for the element specified by XPath.
set_valueThis method sets a new value for the element specified by XPath.
start_arrayThis method writes the opening bracket of a JSON array.
start_objectThis event writes the opening brace of a JSON object.
try_xpathThis method navigates to the specified XPath if it exists.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

on_charactersThis event is fired for plaintext segments of the input stream.
on_end_documentThis event fires when the end of a JSON document is encountered.
on_end_elementThis event is fired when an end-element tag is encountered.
on_errorFired when information is available about errors during data delivery.
on_ignorable_whitespaceThis event is fired when a section of ignorable whitespace is encountered.
on_jsonThis event fires with the JSON data being written.
on_start_documentThis event fires when the start of a new JSON document is encountered.
on_start_elementThis event is fired when a new element is encountered in the document.

Config Settings


The following is a list of config settings for the class with short descriptions. Click on the links for further details.

CacheContentIf true, the original JSON is stored internally in a buffer.
CloseInputStreamAfterProcessDetermines whether or not the input stream is closed after processing.
CloseOutputStreamAfterProcessDetermines whether or not the output stream is closed after processing.
ElementXPathThe XPath value for the current element in the document.
EscapeForwardSlashesWhether to escape forward slashes when writing a JSON object.
InputFormatSpecifies the input format used in JSON streaming.
PrettyPrintDetermines whether output is on one line or "pretty printed".
RecordEndDelimiterThe character sequence after the end of a JSON document.
RecordStartDelimiterThe character sequence before the start of a JSON document.
StringProcessingOptionsDefines options to use when processing string values.
XPathNotationSpecifies the expected format when setting XPath.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
MaskSensitiveDataWhether sensitive data is masked in log messages.
ProcessIdleEventsWhether the class uses its internal event loop to process events when the main thread is idle.
SelectWaitMillisThe length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.
UseFIPSCompliantAPITells the class whether or not to use FIPS certified APIs.
UseInternalSecurityAPIWhether or not to use the system security libraries or an internal implementation.

build_dom Property

When True, an internal object model of the JSON document is created.

Syntax

def get_build_dom() -> bool: ...
def set_build_dom(value: bool) -> None: ...

build_dom = property(get_build_dom, set_build_dom)

Default Value

TRUE

Remarks

Set this property to True when you need to browse the current document through xpath.

input_data Property

This property includes the JSON data to parse.

Syntax

def get_input_data() -> str: ...
def set_input_data(value: str) -> None: ...

input_data = property(get_input_data, set_input_data)

Default Value

""

Remarks

This property specifies the JSON to be processed. Set this property before calling parse.

This may be set to a complete JSON document, or partial data. When setting partial data, call parse after each chunk of data is set. For instance:

//Parse the following in chunks: { "data": 1} json.InputData = "{ \"data\"" json.Parse(); json.InputData = ": 1}" json.Parse();

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.

input_file Property

This property specifies the file to process.

Syntax

def get_input_file() -> str: ...
def set_input_file(value: str) -> None: ...

input_file = property(get_input_file, set_input_file)

Default Value

""

Remarks

This property specifies the file to be processed. Set this property to the full or relative path to the file that will be processed.

After setting this property, call parse to parse the document.

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.

output_data Property

This property includes the output JSON after processing.

Syntax

def get_output_data() -> str: ...
def set_output_data(value: str) -> None: ...

output_data = property(get_output_data, set_output_data)

Default Value

""

Remarks

This property contains the resultant JSON after processing.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

  • output_file
  • output_data: The output data are written to this property if no other destination is specified.

output_file Property

This is the path to a local file where the output will be written.

Syntax

def get_output_file() -> str: ...
def set_output_file(value: str) -> None: ...

output_file = property(get_output_file, set_output_file)

Default Value

""

Remarks

This property specifies the file to which the output will be written. This may be set to an absolute or relative path.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

  • output_file
  • output_data: The output data are written to this property if no other destination is specified.

overwrite Property

This property indicates whether or not the class should overwrite files.

Syntax

def get_overwrite() -> bool: ...
def set_overwrite(value: bool) -> None: ...

overwrite = property(get_overwrite, set_overwrite)

Default Value

FALSE

Remarks

This property indicates whether or not the class will overwrite output_file. If overwrite is False, an error will be thrown whenever output_file exists before an operation. The default value is False.

validate Property

This property controls whether documents are validated during parsing.

Syntax

def get_validate() -> bool: ...
def set_validate(value: bool) -> None: ...

validate = property(get_validate, set_validate)

Default Value

TRUE

Remarks

When True (default), the document will be validated during parsing. To disable validation set validate to False. Disabling validation may be useful in cases in which data can still be parsed even if the document is not well formed.

xchild_count Property

The number of records in the XChild arrays.

Syntax

def get_xchild_count() -> int: ...
def set_xchild_count(value: int) -> None: ...

xchild_count = property(get_xchild_count, set_xchild_count)

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at xchild_count - 1.

xchild_element_type Property

The ElementType property indicates the data type of the element.

Syntax

def get_xchild_element_type(xchild_index: int) -> int: ...

Default Value

0

Remarks

The xchild_element_type property indicates the data type of the element.

Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

The xchild_index parameter specifies the index of the item in the array. The size of the array is controlled by the xchild_count property.

This property is read-only.

xchild_name Property

The Name property provides the name of the element.

Syntax

def get_xchild_name(xchild_index: int) -> str: ...

Default Value

""

Remarks

The xchild_name property provides the name of the element. For elements within an array, the xchild_name property will be empty.

The xchild_index parameter specifies the index of the item in the array. The size of the array is controlled by the xchild_count property.

This property is read-only.

xchild_x_text Property

This property contains the text of the element.

Syntax

def get_xchild_x_text(xchild_index: int) -> str: ...

Default Value

""

Remarks

This property contains the text of the element.

The xchild_index parameter specifies the index of the item in the array. The size of the array is controlled by the xchild_count property.

This property is read-only.

xelement Property

This property includes the name of the current element.

Syntax

def get_xelement() -> str: ...
def set_xelement(value: str) -> None: ...

xelement = property(get_xelement, set_xelement)

Default Value

""

Remarks

This property contains the name of the current element. The current element is specified through the xpath property.

xelement_type Property

This property indicates the data type of the current element.

Syntax

def get_xelement_type() -> int: ...

xelement_type = property(get_xelement_type, None)

Default Value

0

Remarks

This property specifies the data type of the current element. After setting xpath, this property is populated. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

Note: This property is not applicable when parsing a document and build_dom is False.

This property is read-only.

xerror_path Property

This property includes an XPath to check the server response for errors.

Syntax

def get_xerror_path() -> str: ...
def set_xerror_path(value: str) -> None: ...

xerror_path = property(get_xerror_path, set_xerror_path)

Default Value

""

Remarks

This property contains an XPath to check the server response for errors. If the XPath exists, an exception will be thrown containing the value of the element at the path.

xparent Property

The parent of the current element.

Syntax

def get_xparent() -> str: ...

xparent = property(get_xparent, None)

Default Value

""

Remarks

This property contains the parent of the current element. The current element is specified via the xpath property.

This property is read-only.

xpath Property

This property provides a way to point to a specific element in the response.

Syntax

def get_xpath() -> str: ...
def set_xpath(value: str) -> None: ...

xpath = property(get_xpath, set_xpath)

Default Value

""

Remarks

xpath may be set to navigate to specific elements within the JSON document. This will be the path to a specified value within the document. Because 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 before parsing the document for the xpath functionality to be available.

The xpath property accepts both XPath and JSONPath formats. Please review the following notes on both formats.

XPath

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 xpath 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 xpath is set to a valid path, the following properties are updated:

build_dom must be set to True before parsing the document for the xpath functionality to be available.

Simple JSON Document

{
  "firstlevel": {
    "one": "value",
    "two": ["first", "second"],
    "three": "value three"
  }
}
Example 1. 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 previous examples, this means all paths will begin with "/json".

JSONPath

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

$.store.book[0].title
or in bracket-notation, as follows:
$['store']['book'][0]['title']

After setting xpath, the following properties are populated:

Example 2. Setting JSONPath:

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"; Console.WriteLine(json.XText); //Output //"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); //Output //Child Count: 4 //author: "Nigel Rees" Get the price of the second book:

json.XPath = "$['store']['book'][1]['price']"; Console.WriteLine(json.XText); //Output //12.99 Get the second to last book's author:

json.XPath = "$['store']['book'][last() - 1]['author']"; Console.WriteLine(json.XText); Console.WriteLine(json.XPath); //Note that "last() - 1" is resolved to "3". //Output //"Herman Melville" //$['store']['book'][3]['author'] Display the full subtree at the current path:

json.XPath = "$.store.book[0]"; Console.WriteLine(json.XSubTree); //Output // { // "category": "reference", // "author": "Nigel Rees", // "title": "Sayings of the Century", // "price": 8.95 // }

xsub_tree Property

This property includes a snapshot of the current element in the document.

Syntax

def get_xsub_tree() -> str: ...

xsub_tree = property(get_xsub_tree, None)

Default Value

""

Remarks

The current element is specified through this property. For this property to work, you must have the CacheContent set to True.

This property is read-only.

xtext Property

This property includes the text of the current element.

Syntax

def get_xtext() -> str: ...
def set_xtext(value: str) -> None: ...

xtext = property(get_xtext, set_xtext)

Default Value

""

Remarks

This property contains the text of the current element. The current element is specified through the xpath property.

config Method

Sets or retrieves a configuration setting.

Syntax

def config(configuration_string: str) -> str: ...

Remarks

config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

end_array Method

This method writes the closing bracket of a JSON array.

Syntax

def end_array() -> None: ...

Remarks

This method writes the closing bracket of a JSON array to the output. An array must already have been opened by calling start_array.

end_object Method

This method writes the closing brace of a JSON object.

Syntax

def end_object() -> None: ...

Remarks

This method writes the closing brace of a JSON object. An object must have been started previously by calling start_object.

flush Method

This method flushes the parser's or writer's buffers.

Syntax

def flush() -> None: ...

Remarks

When flush is called, the component flushes all of its buffers, firing events as necessary.

When parsing, the end state of the JSON is checked. If validate is also True, the parser verifies that all open elements were closed, returning an error if not.

When writing, the resultant JSON is available in one of the output properties.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

has_xpath Method

This method determines whether a specific element exists in the document.

Syntax

def has_xpath(xpath: str) -> bool: ...

Remarks

This method determines whether a particular XPath exists within the document. This may be used to check if a path exists before setting it through xpath.

This method returns True if the xpath exists, and False if not.

See xpath for details on the XPath syntax.

insert_property Method

This method inserts the specified name and value at the selected position.

Syntax

def insert_property(name: str, value: str, value_type: int, position: int) -> None: ...

Remarks

This method inserts a property and its corresponding value relative to the element specified by xpath. Before calling this method, a valid JSON document must first be loaded by calling parse.

The Name parameter specifies the name of the property.

The Value parameter specifies the value of the property.

The ValueType parameter specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

The Position parameter specifies the position of Value relative to the element specified by xpath. Possible values are as follows:

  • 0 (Before the current element)
  • 1 (After the current element)
  • 2 (The first child of the current element)
  • 3 (The last child of the current element)

See save for details.

insert_value Method

This method inserts the specified value at the selected position.

Syntax

def insert_value(value: str, value_type: int, position: int) -> None: ...

Remarks

This method inserts a value relative to the element specified by xpath. Before calling this method, a valid JSON document must first be loaded by calling parse.

The Value parameter specifies the value of the property.

The ValueType parameter specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

The Position parameter specifies the position of Value relative to the element specified by xpath. Possible values are as follows:

  • 0 (Before the current element)
  • 1 (After the current element)
  • 2 (The first child of the current element)
  • 3 (The last child of the current element)

See save for details.

parse Method

This method parses the specified JSON data.

Syntax

def parse() -> None: ...

Remarks

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, it may be navigated by setting xpath if build_dom is True (default). If build_dom is False, parsed data are accessible only through the events.

The following events will fire during parsing:

If build_dom is True (default), xpath may be set after this method returns. xpath may be set to navigate to specific elements within the JSON document. This will be the path to a specified value within the document. Because 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 before parsing the document for the xpath functionality to be available.

The xpath property accepts both XPath and JSONPath formats. Please review the following notes on both formats.

XPath

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 xpath 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 xpath is set to a valid path, the following properties are updated:

build_dom must be set to True before parsing the document for the xpath functionality to be available.

Simple JSON Document

{
  "firstlevel": {
    "one": "value",
    "two": ["first", "second"],
    "three": "value three"
  }
}
Example 1. 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 previous examples, this means all paths will begin with "/json".

JSONPath

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

$.store.book[0].title
or in bracket-notation, as follows:
$['store']['book'][0]['title']

After setting xpath, the following properties are populated:

Example 2. Setting JSONPath:

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"; Console.WriteLine(json.XText); //Output //"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); //Output //Child Count: 4 //author: "Nigel Rees" Get the price of the second book:

json.XPath = "$['store']['book'][1]['price']"; Console.WriteLine(json.XText); //Output //12.99 Get the second to last book's author:

json.XPath = "$['store']['book'][last() - 1]['author']"; Console.WriteLine(json.XText); Console.WriteLine(json.XPath); //Note that "last() - 1" is resolved to "3". //Output //"Herman Melville" //$['store']['book'][3]['author'] Display the full subtree at the current path:

json.XPath = "$.store.book[0]"; Console.WriteLine(json.XSubTree); //Output // { // "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.

put_name Method

This method writes the name of a property.

Syntax

def put_name(name: str) -> None: ...

Remarks

This method writes the name of a property. The Name parameter specifies the value to write.

put_property Method

This method writes a property and value.

Syntax

def put_property(name: str, value: str, value_type: int) -> None: ...

Remarks

This method writes a property and its corresponding value to the output.

The Name parameter specifies the name of the property.

The Value parameter specifies the value of the property.

The ValueType parameter specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

put_raw Method

This method writes a raw JSON fragment.

Syntax

def put_raw(text: str) -> None: ...

Remarks

This method writes raw data to the output. This may be used to write any data of any format directly to the output.

put_value Method

This method writes a value of a property.

Syntax

def put_value(value: str, value_type: int) -> None: ...

Remarks

This method writes the value of a property to the output. The Value parameter specifies the value. The ValueType parameter specifies the type of data. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

remove Method

This method removes the element or value set in XPath.

Syntax

def remove() -> None: ...

Remarks

This method removes the current object at the specified xpath. This is used when editing previously loaded JSON documents.

See save for details.

reset Method

This method resets the class.

Syntax

def reset() -> None: ...

Remarks

This method resets the JSON parser.

save Method

This method saves the modified JSON document.

Syntax

def save() -> None: ...

Remarks

This method saves the modified JSON data. This is used after editing a previously loaded JSON document.

After loading a JSON document with parse the document may be edited. The class supports inserting new values, renaming or overwriting existing values, and removing values. After editing is complete, call save to output the updated JSON document.

The following methods are applicable when modifying a JSON document:

When save is called, the modified JSON is written to the specified output location.

Output Properties

The class will determine the destination of the output based on which properties are set.

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

Example 1. Inserting New Values:

To insert new values in a JSON document, first load the existing document with parse. Next set xpath to the sibling or parent of the data to be inserted. Call insert_property or insert_value and pass the ValueType and Position parameters to indicate the type of data being inserted and the position.

The ValueType parameter of these methods specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

The Position parameter of these methods specifies the position of Value. Possible values are as follows:

  • 0 (Before the current element)
  • 1 (After the current element)
  • 2 (The first child of the current element)
  • 3 (The last child of the current element)

For example:

Given the following JSON:

{
    "store": {
        "books": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
            }
        ]    
    }
}

Insert a new property "price" for each book:

json.XPath = "/json/store/books/[1]"; json.InsertProperty("price", "8.95", 3, 3); //3 - Number, 3 - Last Child json.XPath = "/json/store/books/[2]"; json.InsertProperty("price", "12.99", 3, 3); //3 - Number, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "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
    }
    ]
  }
}

To add a new book to the array:

json.XPath = "/json/store/books"; json.InsertValue("", 0, 3); //0 - Object, 3 - Last Child json.XPath = "/json/store/books/[3]"; json.InsertProperty("category", "fiction", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("author", "Herman Melville", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("title", "Moby Dick", 2, 3); //2 - String, 3 - Last Child json.InsertProperty("price", "8.99", 3, 3); //3 - Number, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "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",
      "price": 8.99
    }
    ]
  }
}

To add a new array property to each book:

json.XPath = "/json/store/books/[1]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[1]/tags"; json.InsertValue("quotes", 2, 3); //2 - String, 3 - Last Child json.InsertValue("british", 2, 3); //2 - String, 3 - Last Child json.XPath = "/json/store/books/[2]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[2]/tags"; json.InsertValue("trilogy", 2, 3); //2 - String, 3 - Last Child json.InsertValue("war", 2, 3); //2 - String, 3 - Last Child json.XPath = "/json/store/books/[3]"; json.InsertProperty("tags", "", 1, 2); //1 - Array, 2 - First Child json.XPath = "/json/store/books/[3]/tags"; json.InsertValue("classic", 2, 3); //2 - String, 3 - Last Child json.InsertValue("whales", 2, 3); //2 - String, 3 - Last Child json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["quotes", "british"],
      "category": "reference",
      "author": "Nigel Rees",
      "title": "Sayings of the Century",
      "price": 8.95
    },
    {
      "tags": ["trilogy", "war"],
      "category": "fiction",
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "category": "fiction",
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

Example 2. Removing Values:

To remove existing values, set xpath and call the remove method. Continuing with example 1, to remove the first book: json.XPath = "/json/store/books/[1]"; json.Remove(); json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["trilogy", "war"],
      "category": "fiction",
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "category": "fiction",
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

To remove the "category" properties from each book: json.XPath = "/json/store/books/[1]/category"; json.Remove(); json.XPath = "/json/store/books/[2]/category"; json.Remove(); json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "tags": ["trilogy", "war"],
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
    {
      "tags": ["classic", "whales"],
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 8.99
    }
    ]
  }
}

Example 3. Updating Existing Names and Values:

The set_name and set_value methods may be used to modify existing names and values. Continuing with the preceding JSON in example 2, to rename "tags" to "meta" and update values within the array and prices:

//Rename "tags" to "meta" for 1st book json.XPath = "/json/store/books/[1]/tags"; json.SetName("meta"); //Update Price json.XPath = "/json/store/books/[1]/price"; json.SetValue("13.99", 3); //3 - Number //Rename "tags" to "meta" for 2nd book json.XPath = "/json/store/books/[2]/tags"; json.SetName("meta"); //Update tag "whales" to "revenge" json.XPath = "/json/store/books/[2]/meta/[2]"; json.SetValue("revenge", 2); //2 - String //Update Price json.XPath = "/json/store/books/[2]/price"; json.SetValue("9.99", 3); //3 - Number json.Save();

Produces the JSON:

{
  "store": {
    "books": [
    {
      "meta": ["trilogy", "war"],
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 13.99
    },
    {
      "meta": ["classic", "revenge"],
      "author": "Herman Melville",
      "title": "Moby Dick",
      "price": 9.99
    }
    ]
  }
}

set_name Method

This method sets a new name for the element specified by XPath.

Syntax

def set_name(name: str) -> None: ...

Remarks

This method sets a new name for the element specified in xpath. This is used to modify an existing JSON document.

The Name parameter specifies the new name of the element.

See save for details.

set_value Method

This method sets a new value for the element specified by XPath.

Syntax

def set_value(value: str, value_type: int) -> None: ...

Remarks

This method sets a new value for the element specified in xpath. This is used to modify an existing JSON document.

Value specifies the new value.

ValueType specifies the type of the value. Possible values are as follows:

  • 0 (Object)
  • 1 (Array)
  • 2 (String)
  • 3 (Number)
  • 4 (Bool)
  • 5 (Null)
  • 6 (Raw)

See save for details.

start_array Method

This method writes the opening bracket of a JSON array.

Syntax

def start_array() -> None: ...

Remarks

This method writes the opening bracket of a JSON array to the output. To close the array, call end_array.

start_object Method

This event writes the opening brace of a JSON object.

Syntax

def start_object() -> None: ...

Remarks

This method writes the opening brace of a JSON object to the output. To close the object, call end_object.

try_xpath Method

This method navigates to the specified XPath if it exists.

Syntax

def try_xpath(xpath: str) -> bool: ...

Remarks

This method will attempt to navigate to the specified XPath parameter if it exists within the document.

If the XPath exists, the xpath property will be updated and this method returns True.

If the XPath does not exist, the xpath property is not updated and this method returns False.

on_characters Event

This event is fired for plaintext segments of the input stream.

Syntax

class JSONCharactersEventParams(object):
  @property
  def text() -> str: ...

# In class JSON:
@property
def on_characters() -> Callable[[JSONCharactersEventParams], None]: ...
@on_characters.setter
def on_characters(event_hook: Callable[[JSONCharactersEventParams], None]) -> None: ...

Remarks

The on_characters event provides the plaintext content of the JSON document (i.e., the text inside the elements). The text is provided through the Text parameter.

The text includes white space as well as end-of-line characters, except for ignorable whitespace, which is fired through the on_ignorable_whitespace event.

on_end_document Event

This event fires when the end of a JSON document is encountered.

Syntax

class JSONEndDocumentEventParams(object):
# In class JSON:
@property
def on_end_document() -> Callable[[JSONEndDocumentEventParams], None]: ...
@on_end_document.setter
def on_end_document(event_hook: Callable[[JSONEndDocumentEventParams], None]) -> None: ...

Remarks

This event fires when parsing of a JSON document ends. This event may fire multiple times if InputFormat is set to a value that accepts multiple JSON documents.

on_end_element Event

This event is fired when an end-element tag is encountered.

Syntax

class JSONEndElementEventParams(object):
  @property
  def element() -> str: ...

# In class JSON:
@property
def on_end_element() -> Callable[[JSONEndElementEventParams], None]: ...
@on_end_element.setter
def on_end_element(event_hook: Callable[[JSONEndElementEventParams], None]) -> None: ...

Remarks

The on_end_element event is fired when the end of an element is found in the document.

The element name is provided by the Element parameter.

on_error Event

Fired when information is available about errors during data delivery.

Syntax

class JSONErrorEventParams(object):
  @property
  def error_code() -> int: ...

  @property
  def description() -> str: ...

# In class JSON:
@property
def on_error() -> Callable[[JSONErrorEventParams], None]: ...
@on_error.setter
def on_error(event_hook: Callable[[JSONErrorEventParams], None]) -> None: ...

Remarks

The on_error event is fired in case of exceptional conditions during message processing. Normally the class fails with an error.

The ErrorCode parameter contains an error code, and the Description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

on_ignorable_whitespace Event

This event is fired when a section of ignorable whitespace is encountered.

Syntax

class JSONIgnorableWhitespaceEventParams(object):
  @property
  def text() -> str: ...

# In class JSON:
@property
def on_ignorable_whitespace() -> Callable[[JSONIgnorableWhitespaceEventParams], None]: ...
@on_ignorable_whitespace.setter
def on_ignorable_whitespace(event_hook: Callable[[JSONIgnorableWhitespaceEventParams], None]) -> None: ...

Remarks

The ignorable whitespace section is provided by the Text parameter.

on_json Event

This event fires with the JSON data being written.

Syntax

class JSONJSONEventParams(object):
  @property
  def text() -> str: ...

# In class JSON:
@property
def on_json() -> Callable[[JSONJSONEventParams], None]: ...
@on_json.setter
def on_json(event_hook: Callable[[JSONJSONEventParams], None]) -> None: ...

Remarks

This event fires when output data are written.

Text contains the JSON data currently being written.

on_start_document Event

This event fires when the start of a new JSON document is encountered.

Syntax

class JSONStartDocumentEventParams(object):
# In class JSON:
@property
def on_start_document() -> Callable[[JSONStartDocumentEventParams], None]: ...
@on_start_document.setter
def on_start_document(event_hook: Callable[[JSONStartDocumentEventParams], None]) -> None: ...

Remarks

This event fires when parsing of a JSON document begins. This event may fire multiple times if InputFormat is set to a value that accepts multiple JSON documents.

on_start_element Event

This event is fired when a new element is encountered in the document.

Syntax

class JSONStartElementEventParams(object):
  @property
  def element() -> str: ...

# In class JSON:
@property
def on_start_element() -> Callable[[JSONStartElementEventParams], None]: ...
@on_start_element.setter
def on_start_element(event_hook: Callable[[JSONStartElementEventParams], None]) -> None: ...

Remarks

The on_start_element event is fired when a new element is found in the document.

The element name is provided through the Element parameter.

JSON Config Settings

The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the config method.

JSON Config Settings

CacheContent:   If true, the original JSON is stored internally in a buffer.

This configuration setting controls whether or not the class retains the entire original JSON data in a buffer. This is used to retain the original JSON as opposed to returning generated JSON after parsing. The default value is True.

CloseInputStreamAfterProcess:   Determines whether or not the input stream is closed after processing.

This configuration setting determines whether or not the input stream set by set_input_stream is closed after processing is complete. The default value is True.

CloseOutputStreamAfterProcess:   Determines whether or not the output stream is closed after processing.

This configuration setting determines whether or not the output stream set by set_output_stream is closed after processing is complete. The default value is True.

ElementXPath:   The XPath value for the current element in the document.

This configuration setting holds the current XPath value when the document is parsed. When queried from inside the on_start_element event, the corresponding element's XPath value will be returned. For instance:

string elementXPath = json.Config("ElementXPath");

Note: The build_dom property must be set to False.

EscapeForwardSlashes:   Whether to escape forward slashes when writing a JSON object.

This configuration setting specifies whether forward slashes (/) are escaped when creating a JSON object using the class. This does not affect parsing of JSON. It is applicable only when JSON values are written.

InputFormat:   Specifies the input format used in JSON streaming.

This configuration setting specifies how JSON documents are formatted as they are input to the class. This setting is designed for use when data are provided via JSON streaming. This means multiple documents may be parsed by the class. This setting is applicable only when build_dom is set to False. Possible values are as follows:

Value Description
0 (None - default) Only a single JSON document is expected. Use this when a single JSON document is being parsed (most cases).
1 (Line Delimited) Multiple documents are separated by carriage return (CR), line feed (LF), or CRLF character sequences.
2 (Record Separated) A defined start and end delimiter separate documents. See RecordStartDelimiter and RecordEndDelimiter.
3 (Concatenated) New documents begin immediately after the previous documents end; no characters or delimiters separate the documents.

PrettyPrint:   Determines whether output is on one line or "pretty printed".

The value of this configuration setting determines whether output is generated as a single line of JSON or as multiple "pretty printed" lines. The following example code, provides a better understanding of this configuration setting: json.Config("PrettyPrint=true"); // false json.StartObject(); json.PutName("data"); json.StartObject(); json.PutProperty("id", "3", 3); json.PutProperty("first_name", "Emma", 2); json.PutProperty("last_name", "Wong", 2); json.PutProperty("avatar", "https://s3.amazonaws.com/uifaces/faces/twitter/olegpogodaev/128.jpg", 2); json.EndObject(); json.EndObject(); json.Flush(); Console.WriteLine(json.OutputData); With PrettyPrint set to False (the default), the output would look like this:

{"data":{"id":3,"first_name":"Emma","last_name":"Wong","avatar":"https:\/\/s3.amazonaws.com\/uifaces\/faces\/twitter\/olegpogodaev\/128.jpg"}}
With PrettyPrint set to True, the output instead would look like this:
{
  "data": {
    "id": 3,
    "first_name": "Emma",
    "last_name": "Wong",
    "avatar": "https:\/\/s3.amazonaws.com\/uifaces\/faces\/twitter\/olegpogodaev\/128.jpg"
  }
}
The default value is False.
RecordEndDelimiter:   The character sequence after the end of a JSON document.

This configuration setting is used in conjunction with InputFormat to specify the character sequence that is expected after the end of a JSON document.

RecordStartDelimiter:   The character sequence before the start of a JSON document.

This configuration setting is used in conjunction with InputFormat to specify the character sequence that is expected before the start of a JSON document.

StringProcessingOptions:   Defines options to use when processing string values.

This configuration setting determines what additional processing is performed on string values during parsing. By default, no additional processing is performed and the string is returned as is from the document. Strings also may be unquoted, unescaped, or both. Possible values follow:

0 (none - default)No additional processing is performed.
1 (unquote) Strings are unquoted.
2 (unescape) Any escaped sequences are unescaped.
3 (unquote and unescape) Values are both unquoted and unescaped.
For instance, given the JSON element:
"example" : "value\ntest"
The following table shows the resulting value for the XText of the element:
StringProcessingOptionOutput
0 (none)
"value\ntest"
1 (unquote)
value\ntest
2 (unescape)
"value
test"
3 (unquote and unescape)
value
test
XPathNotation:   Specifies the expected format when setting XPath.

This configuration setting optionally specifies the expected input format when setting xpath. Possible values follow:

  • 0 (Auto - default)
  • 1 (XPath)
  • 2 (JSONPath)
In most cases, the default of 0 (Auto) is sufficient. The class will determine whether the path value is in XPath or JSONPath format automatically. If desired, the type may be explicitly set to either XPath or JSONPath using the values above.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

CodePage:   The system code page used for Unicode to Multibyte translations.

The default code page is Unicode UTF-8 (65001).

The following is a list of valid code page identifiers:

IdentifierName
037IBM EBCDIC - U.S./Canada
437OEM - United States
500IBM EBCDIC - International
708Arabic - ASMO 708
709Arabic - ASMO 449+, BCON V4
710Arabic - Transparent Arabic
720Arabic - Transparent ASMO
737OEM - Greek (formerly 437G)
775OEM - Baltic
850OEM - Multilingual Latin I
852OEM - Latin II
855OEM - Cyrillic (primarily Russian)
857OEM - Turkish
858OEM - Multilingual Latin I + Euro symbol
860OEM - Portuguese
861OEM - Icelandic
862OEM - Hebrew
863OEM - Canadian-French
864OEM - Arabic
865OEM - Nordic
866OEM - Russian
869OEM - Modern Greek
870IBM EBCDIC - Multilingual/ROECE (Latin-2)
874ANSI/OEM - Thai (same as 28605, ISO 8859-15)
875IBM EBCDIC - Modern Greek
932ANSI/OEM - Japanese, Shift-JIS
936ANSI/OEM - Simplified Chinese (PRC, Singapore)
949ANSI/OEM - Korean (Unified Hangul Code)
950ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC)
1026IBM EBCDIC - Turkish (Latin-5)
1047IBM EBCDIC - Latin 1/Open System
1140IBM EBCDIC - U.S./Canada (037 + Euro symbol)
1141IBM EBCDIC - Germany (20273 + Euro symbol)
1142IBM EBCDIC - Denmark/Norway (20277 + Euro symbol)
1143IBM EBCDIC - Finland/Sweden (20278 + Euro symbol)
1144IBM EBCDIC - Italy (20280 + Euro symbol)
1145IBM EBCDIC - Latin America/Spain (20284 + Euro symbol)
1146IBM EBCDIC - United Kingdom (20285 + Euro symbol)
1147IBM EBCDIC - France (20297 + Euro symbol)
1148IBM EBCDIC - International (500 + Euro symbol)
1149IBM EBCDIC - Icelandic (20871 + Euro symbol)
1200Unicode UCS-2 Little-Endian (BMP of ISO 10646)
1201Unicode UCS-2 Big-Endian
1250ANSI - Central European
1251ANSI - Cyrillic
1252ANSI - Latin I
1253ANSI - Greek
1254ANSI - Turkish
1255ANSI - Hebrew
1256ANSI - Arabic
1257ANSI - Baltic
1258ANSI/OEM - Vietnamese
1361Korean (Johab)
10000MAC - Roman
10001MAC - Japanese
10002MAC - Traditional Chinese (Big5)
10003MAC - Korean
10004MAC - Arabic
10005MAC - Hebrew
10006MAC - Greek I
10007MAC - Cyrillic
10008MAC - Simplified Chinese (GB 2312)
10010MAC - Romania
10017MAC - Ukraine
10021MAC - Thai
10029MAC - Latin II
10079MAC - Icelandic
10081MAC - Turkish
10082MAC - Croatia
12000Unicode UCS-4 Little-Endian
12001Unicode UCS-4 Big-Endian
20000CNS - Taiwan
20001TCA - Taiwan
20002Eten - Taiwan
20003IBM5550 - Taiwan
20004TeleText - Taiwan
20005Wang - Taiwan
20105IA5 IRV International Alphabet No. 5 (7-bit)
20106IA5 German (7-bit)
20107IA5 Swedish (7-bit)
20108IA5 Norwegian (7-bit)
20127US-ASCII (7-bit)
20261T.61
20269ISO 6937 Non-Spacing Accent
20273IBM EBCDIC - Germany
20277IBM EBCDIC - Denmark/Norway
20278IBM EBCDIC - Finland/Sweden
20280IBM EBCDIC - Italy
20284IBM EBCDIC - Latin America/Spain
20285IBM EBCDIC - United Kingdom
20290IBM EBCDIC - Japanese Katakana Extended
20297IBM EBCDIC - France
20420IBM EBCDIC - Arabic
20423IBM EBCDIC - Greek
20424IBM EBCDIC - Hebrew
20833IBM EBCDIC - Korean Extended
20838IBM EBCDIC - Thai
20866Russian - KOI8-R
20871IBM EBCDIC - Icelandic
20880IBM EBCDIC - Cyrillic (Russian)
20905IBM EBCDIC - Turkish
20924IBM EBCDIC - Latin-1/Open System (1047 + Euro symbol)
20932JIS X 0208-1990 & 0121-1990
20936Simplified Chinese (GB2312)
21025IBM EBCDIC - Cyrillic (Serbian, Bulgarian)
21027Extended Alpha Lowercase
21866Ukrainian (KOI8-U)
28591ISO 8859-1 Latin I
28592ISO 8859-2 Central Europe
28593ISO 8859-3 Latin 3
28594ISO 8859-4 Baltic
28595ISO 8859-5 Cyrillic
28596ISO 8859-6 Arabic
28597ISO 8859-7 Greek
28598ISO 8859-8 Hebrew
28599ISO 8859-9 Latin 5
28605ISO 8859-15 Latin 9
29001Europa 3
38598ISO 8859-8 Hebrew
50220ISO 2022 Japanese with no halfwidth Katakana
50221ISO 2022 Japanese with halfwidth Katakana
50222ISO 2022 Japanese JIS X 0201-1989
50225ISO 2022 Korean
50227ISO 2022 Simplified Chinese
50229ISO 2022 Traditional Chinese
50930Japanese (Katakana) Extended
50931US/Canada and Japanese
50933Korean Extended and Korean
50935Simplified Chinese Extended and Simplified Chinese
50936Simplified Chinese
50937US/Canada and Traditional Chinese
50939Japanese (Latin) Extended and Japanese
51932EUC - Japanese
51936EUC - Simplified Chinese
51949EUC - Korean
51950EUC - Traditional Chinese
52936HZ-GB2312 Simplified Chinese
54936Windows XP: GB18030 Simplified Chinese (4 Byte)
57002ISCII Devanagari
57003ISCII Bengali
57004ISCII Tamil
57005ISCII Telugu
57006ISCII Assamese
57007ISCII Oriya
57008ISCII Kannada
57009ISCII Malayalam
57010ISCII Gujarati
57011ISCII Punjabi
65000Unicode UTF-7
65001Unicode UTF-8
The following is a list of valid code page identifiers for Mac OS only:
IdentifierName
1ASCII
2NEXTSTEP
3JapaneseEUC
4UTF8
5ISOLatin1
6Symbol
7NonLossyASCII
8ShiftJIS
9ISOLatin2
10Unicode
11WindowsCP1251
12WindowsCP1252
13WindowsCP1253
14WindowsCP1254
15WindowsCP1250
21ISO2022JP
30MacOSRoman
10UTF16String
0x90000100UTF16BigEndian
0x94000100UTF16LittleEndian
0x8c000100UTF32String
0x98000100UTF32BigEndian
0x9c000100UTF32LittleEndian
65536Proprietary

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a class is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitiveData:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to True to mask sensitive data. The default is True.

This setting only works on these classes: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.

ProcessIdleEvents:   Whether the class uses its internal event loop to process events when the main thread is idle.

If set to False, the class will not fire internal idle events. Set this to False to use the class in a background thread on Mac OS. By default, this setting is True.

SelectWaitMillis:   The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.

If there are no events to process when do_events is called, the class will wait for the amount of time specified here before returning. The default value is 20.

UseFIPSCompliantAPI:   Tells the class whether or not to use FIPS certified APIs.

When set to True, the class will utilize the underlying operating system's certified APIs. Java editions, regardless of OS, utilize Bouncy Castle Federal Information Processing Standards (FIPS), while all other Windows editions make use of Microsoft security libraries.

FIPS mode can be enabled by setting the UseFIPSCompliantAPI configuration setting to True. This is a static setting that applies to all instances of all classes of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.

For more details, please see the FIPS 140-2 Compliance article.

Note: This setting is applicable only on Windows.

Note: Enabling FIPS compliance requires a special license; please contact sales@nsoftware.com for details.

UseInternalSecurityAPI:   Whether or not to use the system security libraries or an internal implementation.

When set to False, the class will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this configuration setting to True tells the class to use the internal implementation instead of using the system security libraries.

On Windows, this setting is set to False by default. On Linux/macOS, this setting is set to True by default.

To use the system security libraries for Linux, OpenSSL support must be enabled. For more information on how to enable OpenSSL, please refer to the OpenSSL Notes section.

JSON Errors

JSON Errors

10231   Unbalanced element tag.
10232   Invalid JSON markup.
10233   Invalid XPath.
10234   DOM tree unavailable (set BuildDOM to True and reparse).

XML Errors

101   Invalid attribute index.
102   No attributes available.
103   Invalid namespace index.
104   No namespaces available.
105   Invalid element index.
106   No elements available.
107   Attribute does not exist.
201   Unbalanced element tag.
202   Unknown element prefix (cannot find namespace).
203   Unknown attribute prefix (cannot find namespace).
204   Invalid XML markup.
205   Invalid end state for parser.
206   Document contains unbalanced elements.
207   Invalid xpath.
208   No such child.
209   Top element does not match start of path.
210   DOM tree unavailable (set build_dom to True and reparse).
302   Cannot open file.
401   Invalid XML would be generated.
402   An invalid XML name has been specified.