JSON Class
Properties Methods Events Config Settings Errors
The JSON class can be used to parse and write JSON documents.
Syntax
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, BuildDOM 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 BuildDOM is True (default). If BuildDOM is False, parsed data are accessible only through the events.
The following events will fire during parsing:
If BuildDOM 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.
BuildDOM 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. |
BuildDOM 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]/" |
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].titleor 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 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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
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 InsertProperty or InsertValue 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 SetName and SetValue 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.
BuildDOM | When True, an internal object model of the JSON document is created. |
InputData | This property includes the JSON data to parse. |
InputFile | This property specifies the file to process. |
OutputData | This property includes the output JSON after processing. |
OutputFile | This is the path to a local file where the output will be written. |
Overwrite | This property indicates whether or not the class should overwrite files. |
Validate | This property controls whether documents are validated during parsing. |
XChildren | This property includes a collection of child elements of the current element. |
XElement | This property includes the name of the current element. |
XElementType | This property indicates the data type of the current element. |
XErrorPath | This property includes an XPath to check the server response for errors. |
XParent | The parent of the current element. |
XPath | This property provides a way to point to a specific element in the response. |
XSubTree | This property includes a snapshot of the current element in the document. |
XText | This 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.
Config | Sets or retrieves a configuration setting. |
EndArray | This method writes the closing bracket of a JSON array. |
EndObject | This method writes the closing brace of a JSON object. |
Flush | This method flushes the parser's or writer's buffers. |
HasXPath | This method determines whether a specific element exists in the document. |
InsertProperty | This method inserts the specified name and value at the selected position. |
InsertValue | This method inserts the specified value at the selected position. |
Parse | This method parses the specified JSON data. |
PutName | This method writes the name of a property. |
PutProperty | This method writes a property and value. |
PutRaw | This method writes a raw JSON fragment. |
PutValue | This method writes a value of a property. |
Remove | This method removes the element or value set in XPath. |
Reset | This method resets the class. |
Save | This method saves the modified JSON document. |
SetInputStream | This method sets the stream from which the class will read data to parse. |
SetName | This method sets a new name for the element specified by XPath. |
SetOutputStream | This method sets the stream to which the class will write the JSON. |
SetValue | This method sets a new value for the element specified by XPath. |
StartArray | This method writes the opening bracket of a JSON array. |
StartObject | This event writes the opening brace of a JSON object. |
TryXPath | This 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.
Characters | This event is fired for plaintext segments of the input stream. |
EndDocument | This event fires when the end of a JSON document is encountered. |
EndElement | This event is fired when an end-element tag is encountered. |
Error | Fired when information is available about errors during data delivery. |
IgnorableWhitespace | This event is fired when a section of ignorable whitespace is encountered. |
JSON | This event fires with the JSON data being written. |
StartDocument | This event fires when the start of a new JSON document is encountered. |
StartElement | This 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.
CacheContent | If true, the original JSON is stored internally in a buffer. |
CloseInputStreamAfterProcess | Determines whether or not the input stream is closed after processing. |
CloseOutputStreamAfterProcess | Determines whether or not the output stream is closed after processing. |
ElementXPath | The XPath value for the current element in the document. |
EscapeForwardSlashes | Whether to escape forward slashes when writing a JSON object. |
InputFormat | Specifies the input format used in JSON streaming. |
PrettyPrint | Determines whether output is on one line or "pretty printed". |
RecordEndDelimiter | The character sequence after the end of a JSON document. |
RecordStartDelimiter | The character sequence before the start of a JSON document. |
StringProcessingOptions | Defines options to use when processing string values. |
XPathNotation | Specifies the expected format when setting XPath. |
BuildDOM Property (JSON Class)
When True, an internal object model of the JSON document is created.
Syntax
ANSI (Cross Platform) int GetBuildDOM();
int SetBuildDOM(int bBuildDOM); Unicode (Windows) BOOL GetBuildDOM();
INT SetBuildDOM(BOOL bBuildDOM);
int ipworksmq_json_getbuilddom(void* lpObj);
int ipworksmq_json_setbuilddom(void* lpObj, int bBuildDOM);
bool GetBuildDOM();
int SetBuildDOM(bool bBuildDOM);
Default Value
TRUE
Remarks
Set this property to True when you need to browse the current document through XPath.
Data Type
Boolean
InputData Property (JSON Class)
This property includes the JSON data to parse.
Syntax
ANSI (Cross Platform) char* GetInputData();
int SetInputData(const char* lpszInputData); Unicode (Windows) LPWSTR GetInputData();
INT SetInputData(LPCWSTR lpszInputData);
char* ipworksmq_json_getinputdata(void* lpObj);
int ipworksmq_json_setinputdata(void* lpObj, const char* lpszInputData);
QString GetInputData();
int SetInputData(QString qsInputData);
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:
- InputFile
- InputData
Data Type
String
InputFile Property (JSON Class)
This property specifies the file to process.
Syntax
ANSI (Cross Platform) char* GetInputFile();
int SetInputFile(const char* lpszInputFile); Unicode (Windows) LPWSTR GetInputFile();
INT SetInputFile(LPCWSTR lpszInputFile);
char* ipworksmq_json_getinputfile(void* lpObj);
int ipworksmq_json_setinputfile(void* lpObj, const char* lpszInputFile);
QString GetInputFile();
int SetInputFile(QString qsInputFile);
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:
- InputFile
- InputData
Data Type
String
OutputData Property (JSON Class)
This property includes the output JSON after processing.
Syntax
ANSI (Cross Platform) char* GetOutputData();
int SetOutputData(const char* lpszOutputData); Unicode (Windows) LPWSTR GetOutputData();
INT SetOutputData(LPCWSTR lpszOutputData);
char* ipworksmq_json_getoutputdata(void* lpObj);
int ipworksmq_json_setoutputdata(void* lpObj, const char* lpszOutputData);
QString GetOutputData();
int SetOutputData(QString qsOutputData);
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
Data Type
String
OutputFile Property (JSON Class)
This is the path to a local file where the output will be written.
Syntax
ANSI (Cross Platform) char* GetOutputFile();
int SetOutputFile(const char* lpszOutputFile); Unicode (Windows) LPWSTR GetOutputFile();
INT SetOutputFile(LPCWSTR lpszOutputFile);
char* ipworksmq_json_getoutputfile(void* lpObj);
int ipworksmq_json_setoutputfile(void* lpObj, const char* lpszOutputFile);
QString GetOutputFile();
int SetOutputFile(QString qsOutputFile);
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
Data Type
String
Overwrite Property (JSON Class)
This property indicates whether or not the class should overwrite files.
Syntax
ANSI (Cross Platform) int GetOverwrite();
int SetOverwrite(int bOverwrite); Unicode (Windows) BOOL GetOverwrite();
INT SetOverwrite(BOOL bOverwrite);
int ipworksmq_json_getoverwrite(void* lpObj);
int ipworksmq_json_setoverwrite(void* lpObj, int bOverwrite);
bool GetOverwrite();
int SetOverwrite(bool bOverwrite);
Default Value
FALSE
Remarks
This property indicates whether or not the class will overwrite OutputFile. If Overwrite is False, an error will be thrown whenever OutputFile exists before an operation. The default value is False.
Data Type
Boolean
Validate Property (JSON Class)
This property controls whether documents are validated during parsing.
Syntax
ANSI (Cross Platform) int GetValidate();
int SetValidate(int bValidate); Unicode (Windows) BOOL GetValidate();
INT SetValidate(BOOL bValidate);
int ipworksmq_json_getvalidate(void* lpObj);
int ipworksmq_json_setvalidate(void* lpObj, int bValidate);
bool GetValidate();
int SetValidate(bool bValidate);
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.
Data Type
Boolean
XChildren Property (JSON Class)
This property includes a collection of child elements of the current element.
Syntax
IPWorksMQList<IPWorksMQJSONElement>* GetXChildren(); int SetXChildren(IPWorksMQList<IPWorksMQJSONElement>* val);
int ipworksmq_json_getxchildcount(void* lpObj);
int ipworksmq_json_setxchildcount(void* lpObj, int iXChildCount);
int ipworksmq_json_getxchildelementtype(void* lpObj, int xchildindex);
char* ipworksmq_json_getxchildname(void* lpObj, int xchildindex);
char* ipworksmq_json_getxchildxtext(void* lpObj, int xchildindex);
int GetXChildCount();
int SetXChildCount(int iXChildCount); int GetXChildElementType(int iXChildIndex); QString GetXChildName(int iXChildIndex); QString GetXChildXText(int iXChildIndex);
Remarks
This property contains a collection of child elements of the current element. The elements are provided in the collection in the same order they are found in the document.
This property is not available at design time.
Data Type
XElement Property (JSON Class)
This property includes the name of the current element.
Syntax
ANSI (Cross Platform) char* GetXElement();
int SetXElement(const char* lpszXElement); Unicode (Windows) LPWSTR GetXElement();
INT SetXElement(LPCWSTR lpszXElement);
char* ipworksmq_json_getxelement(void* lpObj);
int ipworksmq_json_setxelement(void* lpObj, const char* lpszXElement);
QString GetXElement();
int SetXElement(QString qsXElement);
Default Value
""
Remarks
This property contains the name of the current element. The current element is specified through the XPath property.
Data Type
String
XElementType Property (JSON Class)
This property indicates the data type of the current element.
Syntax
ANSI (Cross Platform) int GetXElementType(); Unicode (Windows) INT GetXElementType();
Possible Values
ET_OBJECT(0),
ET_ARRAY(1),
ET_STRING(2),
ET_NUMBER(3),
ET_BOOL(4),
ET_NULL(5)
int ipworksmq_json_getxelementtype(void* lpObj);
int GetXElementType();
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 BuildDOM is False.
This property is read-only.
Data Type
Integer
XErrorPath Property (JSON Class)
This property includes an XPath to check the server response for errors.
Syntax
ANSI (Cross Platform) char* GetXErrorPath();
int SetXErrorPath(const char* lpszXErrorPath); Unicode (Windows) LPWSTR GetXErrorPath();
INT SetXErrorPath(LPCWSTR lpszXErrorPath);
char* ipworksmq_json_getxerrorpath(void* lpObj);
int ipworksmq_json_setxerrorpath(void* lpObj, const char* lpszXErrorPath);
QString GetXErrorPath();
int SetXErrorPath(QString qsXErrorPath);
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.
Data Type
String
XParent Property (JSON Class)
The parent of the current element.
Syntax
ANSI (Cross Platform) char* GetXParent(); Unicode (Windows) LPWSTR GetXParent();
char* ipworksmq_json_getxparent(void* lpObj);
QString GetXParent();
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.
Data Type
String
XPath Property (JSON Class)
This property provides a way to point to a specific element in the response.
Syntax
ANSI (Cross Platform) char* GetXPath();
int SetXPath(const char* lpszXPath); Unicode (Windows) LPWSTR GetXPath();
INT SetXPath(LPCWSTR lpszXPath);
char* ipworksmq_json_getxpath(void* lpObj);
int ipworksmq_json_setxpath(void* lpObj, const char* lpszXPath);
QString GetXPath();
int SetXPath(QString qsXPath);
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.
BuildDOM 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. |
BuildDOM 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]/" |
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].titleor 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
// }
Data Type
String
XSubTree Property (JSON Class)
This property includes a snapshot of the current element in the document.
Syntax
ANSI (Cross Platform) char* GetXSubTree(); Unicode (Windows) LPWSTR GetXSubTree();
char* ipworksmq_json_getxsubtree(void* lpObj);
QString GetXSubTree();
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.
Data Type
String
XText Property (JSON Class)
This property includes the text of the current element.
Syntax
ANSI (Cross Platform) char* GetXText();
int SetXText(const char* lpszXText); Unicode (Windows) LPWSTR GetXText();
INT SetXText(LPCWSTR lpszXText);
char* ipworksmq_json_getxtext(void* lpObj);
int ipworksmq_json_setxtext(void* lpObj, const char* lpszXText);
QString GetXText();
int SetXText(QString qsXText);
Default Value
""
Remarks
This property contains the text of the current element. The current element is specified through the XPath property.
Data Type
String
Config Method (JSON Class)
Sets or retrieves a configuration setting.
Syntax
ANSI (Cross Platform) char* Config(const char* lpszConfigurationString); Unicode (Windows) LPWSTR Config(LPCWSTR lpszConfigurationString);
char* ipworksmq_json_config(void* lpObj, const char* lpszConfigurationString);
QString Config(const QString& qsConfigurationString);
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.
Error Handling (C++)
This method returns a String value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
EndArray Method (JSON Class)
This method writes the closing bracket of a JSON array.
Syntax
ANSI (Cross Platform) int EndArray(); Unicode (Windows) INT EndArray();
int ipworksmq_json_endarray(void* lpObj);
int EndArray();
Remarks
This method writes the closing bracket of a JSON array to the output. An array must already have been opened by calling StartArray.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
EndObject Method (JSON Class)
This method writes the closing brace of a JSON object.
Syntax
ANSI (Cross Platform) int EndObject(); Unicode (Windows) INT EndObject();
int ipworksmq_json_endobject(void* lpObj);
int EndObject();
Remarks
This method writes the closing brace of a JSON object. An object must have been started previously by calling StartObject.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Flush Method (JSON Class)
This method flushes the parser's or writer's buffers.
Syntax
ANSI (Cross Platform) int Flush(); Unicode (Windows) INT Flush();
int ipworksmq_json_flush(void* lpObj);
int Flush();
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
HasXPath Method (JSON Class)
This method determines whether a specific element exists in the document.
Syntax
ANSI (Cross Platform) bool HasXPath(const char* lpszXPath); Unicode (Windows) INT HasXPath(LPCWSTR lpszXPath);
bool ipworksmq_json_hasxpath(void* lpObj, const char* lpszXPath);
bool HasXPath(const QString& qsXPath);
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.
Error Handling (C++)
This method returns a Boolean value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
InsertProperty Method (JSON Class)
This method inserts the specified name and value at the selected position.
Syntax
ANSI (Cross Platform) int InsertProperty(const char* lpszName, const char* lpszValue, int iValueType, int iPosition); Unicode (Windows) INT InsertProperty(LPCWSTR lpszName, LPCWSTR lpszValue, INT iValueType, INT iPosition);
int ipworksmq_json_insertproperty(void* lpObj, const char* lpszName, const char* lpszValue, int iValueType, int iPosition);
int InsertProperty(const QString& qsName, const QString& qsValue, int iValueType, int iPosition);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
InsertValue Method (JSON Class)
This method inserts the specified value at the selected position.
Syntax
ANSI (Cross Platform) int InsertValue(const char* lpszValue, int iValueType, int iPosition); Unicode (Windows) INT InsertValue(LPCWSTR lpszValue, INT iValueType, INT iPosition);
int ipworksmq_json_insertvalue(void* lpObj, const char* lpszValue, int iValueType, int iPosition);
int InsertValue(const QString& qsValue, int iValueType, int iPosition);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Parse Method (JSON Class)
This method parses the specified JSON data.
Syntax
ANSI (Cross Platform) int Parse(); Unicode (Windows) INT Parse();
int ipworksmq_json_parse(void* lpObj);
int Parse();
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 BuildDOM is True (default). If BuildDOM is False, parsed data are accessible only through the events.
The following events will fire during parsing:
If BuildDOM 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.
BuildDOM 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. |
BuildDOM 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]/" |
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].titleor 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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
PutName Method (JSON Class)
This method writes the name of a property.
Syntax
ANSI (Cross Platform) int PutName(const char* lpszName); Unicode (Windows) INT PutName(LPCWSTR lpszName);
int ipworksmq_json_putname(void* lpObj, const char* lpszName);
int PutName(const QString& qsName);
Remarks
This method writes the name of a property. The Name parameter specifies the value to write.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
PutProperty Method (JSON Class)
This method writes a property and value.
Syntax
ANSI (Cross Platform) int PutProperty(const char* lpszName, const char* lpszValue, int iValueType); Unicode (Windows) INT PutProperty(LPCWSTR lpszName, LPCWSTR lpszValue, INT iValueType);
int ipworksmq_json_putproperty(void* lpObj, const char* lpszName, const char* lpszValue, int iValueType);
int PutProperty(const QString& qsName, const QString& qsValue, int iValueType);
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)
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
PutRaw Method (JSON Class)
This method writes a raw JSON fragment.
Syntax
ANSI (Cross Platform) int PutRaw(const char* lpszText); Unicode (Windows) INT PutRaw(LPCWSTR lpszText);
int ipworksmq_json_putraw(void* lpObj, const char* lpszText);
int PutRaw(const QString& qsText);
Remarks
This method writes raw data to the output. This may be used to write any data of any format directly to the output.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
PutValue Method (JSON Class)
This method writes a value of a property.
Syntax
ANSI (Cross Platform) int PutValue(const char* lpszValue, int iValueType); Unicode (Windows) INT PutValue(LPCWSTR lpszValue, INT iValueType);
int ipworksmq_json_putvalue(void* lpObj, const char* lpszValue, int iValueType);
int PutValue(const QString& qsValue, int iValueType);
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)
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Remove Method (JSON Class)
This method removes the element or value set in XPath.
Syntax
ANSI (Cross Platform) int Remove(); Unicode (Windows) INT Remove();
int ipworksmq_json_remove(void* lpObj);
int Remove();
Remarks
This method removes the current object at the specified XPath. This is used when editing previously loaded JSON documents.
See Save for details.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Reset Method (JSON Class)
This method resets the class.
Syntax
ANSI (Cross Platform) int Reset(); Unicode (Windows) INT Reset();
int ipworksmq_json_reset(void* lpObj);
int Reset();
Remarks
This method resets the JSON parser.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Save Method (JSON Class)
This method saves the modified JSON document.
Syntax
ANSI (Cross Platform) int Save(); Unicode (Windows) INT Save();
int ipworksmq_json_save(void* lpObj);
int Save();
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
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 InsertProperty or InsertValue 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 SetName and SetValue 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 } ] } }
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
SetInputStream Method (JSON Class)
This method sets the stream from which the class will read data to parse.
Syntax
ANSI (Cross Platform) int SetInputStream(IPWorksMQStream* sInputStream); Unicode (Windows) INT SetInputStream(IPWorksMQStream* sInputStream);
int ipworksmq_json_setinputstream(void* lpObj, IPWorksMQStream* sInputStream);
int SetInputStream(IPWorksMQStream* sInputStream);
Remarks
This method specifies a stream from which data will be read when Parse is called.
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.Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
SetName Method (JSON Class)
This method sets a new name for the element specified by XPath.
Syntax
ANSI (Cross Platform) int SetName(const char* lpszName); Unicode (Windows) INT SetName(LPCWSTR lpszName);
int ipworksmq_json_setname(void* lpObj, const char* lpszName);
int SetName(const QString& qsName);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
SetOutputStream Method (JSON Class)
This method sets the stream to which the class will write the JSON.
Syntax
ANSI (Cross Platform) int SetOutputStream(IPWorksMQStream* sOutputStream); Unicode (Windows) INT SetOutputStream(IPWorksMQStream* sOutputStream);
int ipworksmq_json_setoutputstream(void* lpObj, IPWorksMQStream* sOutputStream);
int SetOutputStream(IPWorksMQStream* sOutputStream);
Remarks
This method sets the stream to which the output will be written when writing data.
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:
- OutputFile
- OutputData: The output data are written to this property if no other destination is specified.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
SetValue Method (JSON Class)
This method sets a new value for the element specified by XPath.
Syntax
ANSI (Cross Platform) int SetValue(const char* lpszValue, int iValueType); Unicode (Windows) INT SetValue(LPCWSTR lpszValue, INT iValueType);
int ipworksmq_json_setvalue(void* lpObj, const char* lpszValue, int iValueType);
int SetValue(const QString& qsValue, int iValueType);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
StartArray Method (JSON Class)
This method writes the opening bracket of a JSON array.
Syntax
ANSI (Cross Platform) int StartArray(); Unicode (Windows) INT StartArray();
int ipworksmq_json_startarray(void* lpObj);
int StartArray();
Remarks
This method writes the opening bracket of a JSON array to the output. To close the array, call EndArray.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
StartObject Method (JSON Class)
This event writes the opening brace of a JSON object.
Syntax
ANSI (Cross Platform) int StartObject(); Unicode (Windows) INT StartObject();
int ipworksmq_json_startobject(void* lpObj);
int StartObject();
Remarks
This method writes the opening brace of a JSON object to the output. To close the object, call EndObject.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
TryXPath Method (JSON Class)
This method navigates to the specified XPath if it exists.
Syntax
ANSI (Cross Platform) bool TryXPath(const char* lpszxpath); Unicode (Windows) INT TryXPath(LPCWSTR lpszxpath);
bool ipworksmq_json_tryxpath(void* lpObj, const char* lpszxpath);
bool TryXPath(const QString& qsxpath);
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.
Error Handling (C++)
This method returns a Boolean value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
Characters Event (JSON Class)
This event is fired for plaintext segments of the input stream.
Syntax
ANSI (Cross Platform) virtual int FireCharacters(JSONCharactersEventParams *e);
typedef struct {
const char *Text; int reserved; } JSONCharactersEventParams;
Unicode (Windows) virtual INT FireCharacters(JSONCharactersEventParams *e);
typedef struct {
LPCWSTR Text; INT reserved; } JSONCharactersEventParams;
#define EID_JSON_CHARACTERS 1 virtual INT IPWORKSMQ_CALL FireCharacters(LPSTR &lpszText);
class JSONCharactersEventParams { public: const QString &Text(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void Characters(JSONCharactersEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireCharacters(JSONCharactersEventParams *e) {...}
Remarks
The 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 IgnorableWhitespace event.
EndDocument Event (JSON Class)
This event fires when the end of a JSON document is encountered.
Syntax
ANSI (Cross Platform) virtual int FireEndDocument(JSONEndDocumentEventParams *e);
typedef struct { int reserved; } JSONEndDocumentEventParams;
Unicode (Windows) virtual INT FireEndDocument(JSONEndDocumentEventParams *e);
typedef struct { INT reserved; } JSONEndDocumentEventParams;
#define EID_JSON_ENDDOCUMENT 2 virtual INT IPWORKSMQ_CALL FireEndDocument();
class JSONEndDocumentEventParams { public: int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void EndDocument(JSONEndDocumentEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireEndDocument(JSONEndDocumentEventParams *e) {...}
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.
EndElement Event (JSON Class)
This event is fired when an end-element tag is encountered.
Syntax
ANSI (Cross Platform) virtual int FireEndElement(JSONEndElementEventParams *e);
typedef struct {
const char *Element; int reserved; } JSONEndElementEventParams;
Unicode (Windows) virtual INT FireEndElement(JSONEndElementEventParams *e);
typedef struct {
LPCWSTR Element; INT reserved; } JSONEndElementEventParams;
#define EID_JSON_ENDELEMENT 3 virtual INT IPWORKSMQ_CALL FireEndElement(LPSTR &lpszElement);
class JSONEndElementEventParams { public: const QString &Element(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void EndElement(JSONEndElementEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireEndElement(JSONEndElementEventParams *e) {...}
Remarks
The EndElement event is fired when the end of an element is found in the document.
The element name is provided by the Element parameter.
Error Event (JSON Class)
Fired when information is available about errors during data delivery.
Syntax
ANSI (Cross Platform) virtual int FireError(JSONErrorEventParams *e);
typedef struct {
int ErrorCode;
const char *Description; int reserved; } JSONErrorEventParams;
Unicode (Windows) virtual INT FireError(JSONErrorEventParams *e);
typedef struct {
INT ErrorCode;
LPCWSTR Description; INT reserved; } JSONErrorEventParams;
#define EID_JSON_ERROR 4 virtual INT IPWORKSMQ_CALL FireError(INT &iErrorCode, LPSTR &lpszDescription);
class JSONErrorEventParams { public: int ErrorCode(); const QString &Description(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void Error(JSONErrorEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireError(JSONErrorEventParams *e) {...}
Remarks
The 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.
IgnorableWhitespace Event (JSON Class)
This event is fired when a section of ignorable whitespace is encountered.
Syntax
ANSI (Cross Platform) virtual int FireIgnorableWhitespace(JSONIgnorableWhitespaceEventParams *e);
typedef struct {
const char *Text; int reserved; } JSONIgnorableWhitespaceEventParams;
Unicode (Windows) virtual INT FireIgnorableWhitespace(JSONIgnorableWhitespaceEventParams *e);
typedef struct {
LPCWSTR Text; INT reserved; } JSONIgnorableWhitespaceEventParams;
#define EID_JSON_IGNORABLEWHITESPACE 5 virtual INT IPWORKSMQ_CALL FireIgnorableWhitespace(LPSTR &lpszText);
class JSONIgnorableWhitespaceEventParams { public: const QString &Text(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void IgnorableWhitespace(JSONIgnorableWhitespaceEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireIgnorableWhitespace(JSONIgnorableWhitespaceEventParams *e) {...}
Remarks
The ignorable whitespace section is provided by the Text parameter.
JSON Event (JSON Class)
This event fires with the JSON data being written.
Syntax
ANSI (Cross Platform) virtual int FireJSON(JSONJSONEventParams *e);
typedef struct {
const char *Text; int reserved; } JSONJSONEventParams;
Unicode (Windows) virtual INT FireJSON(JSONJSONEventParams *e);
typedef struct {
LPCWSTR Text; INT reserved; } JSONJSONEventParams;
#define EID_JSON_JSON 6 virtual INT IPWORKSMQ_CALL FireJSON(LPSTR &lpszText);
class JSONJSONEventParams { public: const QString &Text(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void JSONEvt(JSONJSONEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireJSON(JSONJSONEventParams *e) {...}
Remarks
This event fires when output data are written.
Text contains the JSON data currently being written.
StartDocument Event (JSON Class)
This event fires when the start of a new JSON document is encountered.
Syntax
ANSI (Cross Platform) virtual int FireStartDocument(JSONStartDocumentEventParams *e);
typedef struct { int reserved; } JSONStartDocumentEventParams;
Unicode (Windows) virtual INT FireStartDocument(JSONStartDocumentEventParams *e);
typedef struct { INT reserved; } JSONStartDocumentEventParams;
#define EID_JSON_STARTDOCUMENT 7 virtual INT IPWORKSMQ_CALL FireStartDocument();
class JSONStartDocumentEventParams { public: int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void StartDocument(JSONStartDocumentEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireStartDocument(JSONStartDocumentEventParams *e) {...}
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.
StartElement Event (JSON Class)
This event is fired when a new element is encountered in the document.
Syntax
ANSI (Cross Platform) virtual int FireStartElement(JSONStartElementEventParams *e);
typedef struct {
const char *Element; int reserved; } JSONStartElementEventParams;
Unicode (Windows) virtual INT FireStartElement(JSONStartElementEventParams *e);
typedef struct {
LPCWSTR Element; INT reserved; } JSONStartElementEventParams;
#define EID_JSON_STARTELEMENT 8 virtual INT IPWORKSMQ_CALL FireStartElement(LPSTR &lpszElement);
class JSONStartElementEventParams { public: const QString &Element(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void StartElement(JSONStartElementEventParams *e);
// Or, subclass JSON and override this emitter function. virtual int FireStartElement(JSONStartElementEventParams *e) {...}
Remarks
The StartElement event is fired when a new element is found in the document.
The element name is provided through the Element parameter.
JSONElement Type
This type describes an element contained within the JSON document.
Syntax
IPWorksMQJSONElement (declared in ipworksmq.h)
Remarks
This type describes a JSON element.
The elements are inserted into the array in the same order they are found in the document.
Fields
ElementType
int (read-only)
Default Value: 0
The ElementType field 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)
Name
char* (read-only)
Default Value: ""
The Name field provides the name of the element. For elements within an array, the Name field will be empty.
XText
char* (read-only)
Default Value: ""
This field contains the text of the element.
Constructors
JSONElement()
IPWorksMQList Type
Syntax
IPWorksMQList<T> (declared in ipworksmq.h)
Remarks
IPWorksMQList is a generic class that is used to hold a collection of objects of type T, where T is one of the custom types supported by the JSON class.
Methods | |
GetCount |
This method returns the current size of the collection.
int GetCount() {}
|
SetCount |
This method sets the size of the collection. This method returns 0 if setting the size was successful; or -1 if the collection is ReadOnly. When adding additional objects to a collection call this method to specify the new size. Increasing the size of the collection preserves existing objects in the collection.
int SetCount(int count) {}
|
Get |
This method gets the item at the specified position. The index parameter specifies the index of the item in the collection. This method returns NULL if an invalid index is specified.
T* Get(int index) {}
|
Set |
This method sets the item at the specified position. The index parameter specifies the index of the item in the collection that is being set. This method returns -1 if an invalid index is specified. Note: Objects created using the new operator must be freed using the delete operator; they will not be automatically freed by the class.
T* Set(int index, T* value) {}
|
IPWorksMQStream Type
Syntax
IPWorksMQStream (declared in ipworksmq.h)
Remarks
The JSON class includes one or more API members that take a stream object as a parameter. To use such API members, create a concrete class that implements the IPWorksMQStream interface and pass the JSON class an instance of that concrete class.
When implementing the IPWorksMQStream interface's properties and methods, they must behave as described below. If the concrete class's implementation does not behave as expected, undefined behavior may occur.
Properties | |
CanRead |
Whether the stream supports reading.
bool CanRead() { return true; } |
CanSeek |
Whether the stream supports seeking.
bool CanSeek() { return true; } |
CanWrite |
Whether the stream supports writing.
bool CanWrite() { return true; } |
Length |
Gets the length of the stream, in bytes.
int64 GetLength() = 0; |
Methods | |
Close |
Closes the stream, releasing all resources currently allocated for it.
void Close() {} This method is called automatically when an IPWorksMQStream object is deleted. |
Flush |
Forces all data held by the stream's buffers to be written out to storage.
int Flush() { return 0; } Must return 0 if flushing is successful; or -1 if an error occurs or the stream is closed. If the stream does not support writing, this method must do nothing and return 0. |
Read |
Reads a sequence of bytes from the stream and advances the current position within the stream by the number of bytes read.
int Read(void* buffer, int count) = 0; Buffer specifies the buffer to populate with data from the stream. Count specifies the number of bytes that should be read from the stream. Must return the total number of bytes read into Buffer; this may be less than Count if that many bytes are not currently available, or 0 if the end of the stream has been reached. Must return -1 if an error occurs, if reading is not supported, or if the stream is closed. |
Seek |
Sets the current position within the stream based on a particular point of origin.
int64 Seek(int64 offset, int seekOrigin) = 0; Offset specifies the offset in the stream to seek to, relative to SeekOrigin. Valid values for SeekOrigin are:
Must return the new position within the stream; or -1 if an error occurs, if seeking is not supported, or if the stream is closed (however, see note below). If -1 is returned, the current position within the stream must remain unchanged. Note: If the stream is not closed, it must always be possible to call this method with an Offset of 0 and a SeekOrigin of 1 to obtain the current position within the stream, even if seeking is not otherwise supported. |
Write |
Writes a sequence of bytes to the stream and advances the current position within the stream by the number of bytes written.
int Write(const void* buffer, int count) = 0; Buffer specifies the buffer with data to write to the stream. Count specifies the number of bytes that should be written to the stream. Must return the total number of bytes written to the stream; this may be less than Count if that many bytes could not be written. Must return -1 if an error occurs, if writing is not supported, or if the stream is closed. |
Config Settings (JSON Class)
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
string elementXPath = json.Config("ElementXPath");
Note: The BuildDOM property must be set to False.
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. |
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.
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. |
"example" : "value\ntest"The following table shows the resulting value for the XText of the element:
StringProcessingOption | Output |
0 (none) | "value\ntest" |
1 (unquote) | value\ntest |
2 (unescape) | "value test" |
3 (unquote and unescape) | value test |
- 0 (Auto - default)
- 1 (XPath)
- 2 (JSONPath)
Trappable Errors (JSON Class)
Error Handling (C++)
Call the GetLastErrorCode() method to obtain the last called method's result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. Known error codes are listed below. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
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 BuildDOM to True and reparse). |
302 | Cannot open file. |
401 | Invalid XML would be generated. |
402 | An invalid XML name has been specified. |