FB_JsonDomParser

FB_JsonDomParser 1:

This function block is derived from the same internal function block as FB_JsonDynDomParser and thus offers the same interface.

The two derived function blocks differ only in their internal memory management. FB_JsonDomParser is optimized for the fast and efficient parsing and creation of JSON documents that are only changed a little. The function block FB_JsonDynDomParser is recommended for JSON documents to which many changes are made (e.g. the cyclic changing of a specific value in the JSON document).

WARNING

Use of router memory

The function block occupies new memory with each change, e.g. with the methods SetObject() or SetJson(). As a result, the amount of router memory used can grow enormously after repeated actions. This allocated memory is only released again by calling the NewDocument() or ParseDocument() methods.

FB_JsonDomParser 2:

Strings in UTF-8 format

The variables of type STRING used here are based on the UTF-8 format. This STRING formatting is common for MQTT communication as well as for JSON documents.

In order to be able to receive special characters and texts from a wide range of languages, the character set in the Tc3_IotBase and Tc3_JsonXml libraries is not limited to the typical character set of the data type STRING. Instead, the Unicode character set in UTF-8 format is used in conjunction with the data type STRING.

If the ASCII character set is used, there is no difference between the typical formatting of a STRING and the UTF-8 formatting of a STRING.

Further information on the UTF-8 STRING format and available display and conversion options can be found in the documentation for the Tc2_Utilities PLC library.

Syntax

FUNCTION_BLOCK FB_JsonDomParser
VAR_OUTPUT
  initStatus     : HRESULT;
END_VAR

FB_JsonDomParser 3: Outputs

Name

Type

initStatus

HRESULT

FB_JsonDomParser 4: Methods

Name

Description

AddArrayMember

Adds an Array member to a JSON object.

AddBase64Member

Adds a Base64 member to a JSON object.

AddBoolMember

Adds a Bool member to a JSON object.

AddDateTimeMember

Adds a DateTime member to a JSON object.

AddDcTimeMember

Adds a DcTime member to a JSON object.

AddDoubleMember

Adds a Double member to a JSON object.

AddFileTimeMember

Adds a FileTime member to a JSON object.

AddHexBinaryMember

Adds a HexBinary member to a JSON object.

AddInt64Member

Adds an Int64 member to a JSON object.

AddIntMember

Adds an Int member to a JSON object.

AddJsonMember

Adds a JSON member to a JSON object.

AddNullMember

Adds a NULL member to a JSON object.

AddObjectMember

Adds an Object member to a JSON object.

AddStringMember

Adds a String member to a JSON object.

AddUint64Member

Adds an UInt64 member to a JSON object.

AddUintMember

Adds an UInt member to a JSON object.

ArrayBegin

Returns the first element of an array.

ArrayEnd

Returns the last element of an array.

ClearArray

Deletes the contents of an array.

CopyDocument

Copies the contents of the DOM memory into a variable of data type STRING.

CopyJson

Extracts a JSON object from a key and stores it in a variable of data type STRING.

CopyString

Copies the value of a key into a variable of data type STRING.

FindMember

Searches for a specific property in a JSON document.

FindMemberPath

Searches for a specific property in a JSON document (path-specific).

GetArraySize

Returns the number of elements in a JSON array.

GetArrayValue

Returns the value at the current iterator position of an array.

GetArrayValueByIdx

Returns the value of an array at a specified index.

GetBase64

Decodes a Base64 value from a JSON property.

GetBool

Returns the value of a property of the data type BOOL.

GetDateTime

Returns the value of a property of the data type DATE_AND_TIME.

GetDcTime

Returns the value of a property of the data type DCTIME.

GetDocument

Returns the content of the DOM memory as the data type STRING(255).

GetDocumentLength

Returns the length of a JSON document in the DOM memory.

GetDocumentRoot

Returns the root node of a JSON document in the DOM memory.

GetDouble

Returns the value of a property of the data type LREAL.

GetFileTime

Returns the value of a property of the data type DCTIME.

GetHexBinary

Decodes the HexBinary content of a property and writes it to a certain memory address,

GetInt

Returns the value of a property of the data type DINT.

GetInt64

Returns the value of a property of the data type LINT.

GetJson

Returns the value of a property of the data type STRING(255).

GetJsonLength

Returns the length of a property if this is a JSON document.

GetMaxDecimalPlaces

Returns the current setting for MaxDecimalPlaces.

GetMemberName

Returns the name of a JSON property member at the position of the current iterator,

GetMemberValue

Returns the value of a JSON property member at the position of the current iterator,

GetString

Returns the value of a property of the data type STRING(255).

GetStringLength

Returns the length of a property if its value is a string.

GetType

Returns the type of a property value.

GetUint

Returns the value of a property of the data type UDINT.

GetUint64

Returns the value of a property of the data type ULINT.

HasMember

Checks whether a certain property is present in the DOM memory.

IsArray

Checks whether a given property is an array.

IsBase64

Checks whether the value of a given property is of the data type Base64.

IsBool

Checks whether the value of a given property is of the data type BOOL.

IsDouble

Checks whether the value of a given property is of the data type Double (PLC: LREAL).

IsFalse

Checks whether the value of a given property is FALSE.

IsHexBinary

Checks whether the value of a property is in the HexBinary format.

IsInt

Checks whether the value of a given property is of the data type Integer (PLC: DINT) .

IsInt64

Checks whether the value of a given property is of the data type LINT.

IsISO8601TimeFormat

Checks whether the value of a given property has a time format according to ISO8601.

IsNull

Checks whether the value of a given property is NULL.

IsNumber

Checks whether the value of a given property is a numerical value.

IsObject

Checks whether the given property is a further JSON object.

IsString

Checks whether the value of a given property is of the data type STRING.

IsTrue

Checks whether the value of a given property is TRUE.

IsUint

Checks whether the value of a given property is of the data type UDINT.

IsUint64

Checks whether the value of a given property is of the data type ULINT.

LoadDocumentFromFile

Loads a JSON document from a file.

MemberBegin

Returns the first child element below a JSON property.

MemberEnd

Returns the last child element below a JSON property.

NewDocument

Generates a new empty JSON document in the DOM memory.

NextArray

Returns the next element in an array.

NextMember

Returns the next property in a JSON document.

ParseDocument

Loads a JSON object into the DOM memory for further processing.

PopbackValue

Deletes the element at the end of an array.

PushbackBase64Value

Appends a Base64 value to the end of an array.

PushbackBoolValue

Appends a Base64 value to the end of an array.

PushbackDateTimeValue

Appends a value of the data type DATE_AND_TIME to the end of an array.

PushbackDcTimeValue

Appends a value of the data type DCTIME to the end of an array.

PushbackDoubleValue

Appends a value of the data type Double to the end of an array.

PushbackFileTimeValue

Appends a value of the data type FILETIME to the end of an array.

PushbackHexBinaryValue

This method appends a HexBinary-coded value to the end of an array.

PushbackInt64Value

Appends a value of the data type Int64 to the end of an array.

PushbackIntValue

Appends a value of the data type INT to the end of an array.

PushbackJsonValue

Appends a JSON document to the end of an array.

PushbackNullValue

Appends a NULL value to the end of an array.

PushbackStringValue

Appends a value of the data type String to the end of an array.

PushbackUint64Value

Appends a value of the data type UInt64 to the end of an array.

PushbackUintValue

Appends a value of the data type UInt to the end of an array.

RemoveAllMembers

Removes all child elements from a given property.

RemoveArray

Deletes the value of the current array iterator.

RemoveMember

Deletes the property at the current iterator.

RemoveMemberByName

Removes a child element from a given property.

SaveDocumentToFile

Saves a JSON document in a file.

SetArray

Sets the value of a property to the type "Array".

SetBase64

Sets the value of a property to a Base64-coded value.

SetBool

Sets the value of a property to a value of the data type BOOL.

SetDateTime

Sets the value of a property to a value of the data type DATE_AND_TIME.

SetDcTime

Sets the value of a property to a value of the data type DCTIME.

SetDouble

Sets the value of a property to a value of the data type Double.

SetFileTime

Sets the value of a property to a value of the data type FILETIME.

SetHexBinary

Sets the value of a property to a HexBinary-coded value.

SetInt

Sets the value of a property to a value of the data type INT

SetInt64

Sets the value of a property to a value of the data type Int64.

SetJson

Inserts a further JSON document into the value of a property.

SetMaxDecimalPlaces

Sets the current setting for MaxDecimalPlaces.

SetNull

Sets the value of a property to the value NULL.

SetObject

Sets the value of a property to the type "Object".

SetString

Sets the value of a property to a value of the data type STRING.

SetUint

Sets the value of a property to a value of the data type UInt.

SetUint64

Sets the value of a property to a value of the data type UInt64.

Requirements

TwinCAT version

Hardware

Libraries to be integrated

TwinCAT 3.1, Build 4022

x86, x64, ARM

Tc3_JsonXml