JSON Configuration

The component 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 component, access to these internal properties is provided through the Config method.

JSON Configuration Settings

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

This config controls whether or not the component 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.

Charset:   Specifies the charset used when encoding data.

Set this value to specify the charset that is used when encoding data. The default value is UTF-8.

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

Determines whether or not the input stream set by SetInputStream is closed after processing is complete. The default value is True.

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

Determines whether or not the output stream set by SetOutputStream is closed after processing is complete. The default value is True.

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

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


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

Note: The BuildDOM property must be set to false.

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

This setting specifies whether forward slashes (/) are escaped when creating a JSON object using the component. This does not affect parsing of JSON, only when JSON values are written.

InputFormat:   Specifies the input format used in JSON streaming.

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

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 Cr, Lf, or CrLf character sequences.
2 (Record Separated) A defined start and end delimiter separate documents. See RecordStartDelimiter and RecordEndDelimiter.
3 (Concatenated) New documented begin immediately after the previous documents end, there are no characters or delimiters which 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 multiple, "pretty printed" lines. For a better understanding please take the example code below:

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 be 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 would instead be 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 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 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 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 may also be unquoted, unescaped, or both. Possible values are:

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 setting optionally specifies the expected input format when setting XPath. Possible values are:

  • 0 (Auto - default)
  • 1 (XPath)
  • 2 (JSONPath)
In most cases the default of 0 (Auto) is sufficient. The component 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.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 .NET Edition - Version 20.0 [Build 8155]