specification conform JSON for custom structure data types|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
specification conform JSON for custom structure data types
Avatar
Sebastian Schwinn
Member
Members
Forum Posts: 3
Member Since:
03/16/2020
sp_UserOfflineSmall Offline
1
01/16/2023 - 08:24
sp_Permalink sp_Print

Dear all,

I am currently working on an encoder/decoder for structured custom data types and I have some questions about the JSON encoding.
The project is about allowing the encoding payload to be used towards the client via a proprietary interface. The Client has no opportunity to access subsequent informations (metadata, DataTypeDefinition attribute) directly. Thus, the main goal is to achieve reversible JSON encoding without metadata or accessing the DataTypeDefinition attribute. See the example below:

Suppose, there is a data type defined in C as follows:

typedef struct {
    Int32 X;
    Int32 Y;
} Coordinate;

If I want to encode the data of this type in JSON, the specification of Part 6 woudl suggest a solution like:

{ "X":47, "Y":11}

This looks very concise and fine, but the Information is very limited. The client has no Information about the data type name and the field types used. This would result in a request for reading the type DataTypeDefinition attribute, if the client has no prior knowledge of the type.

There is a more profound solution in the OPC UA PubSub Formatter:

{ "Coordinate":{"Value":{"Type":22,"Body":{"Body":{"X":47,"Y":11}}}}}

This solution at least contains the type name information and that it is a structure. Better, but still not all informations in one encoding. So now my question: Is there a defined and specified JSON encoding, where the value, the data type, the data type name and the type and name of each field? Thus, the metadata message aswell as the DataTypeDefinition attribute should not be read. I am looking for something like this:

{
   "Coordinate":{
     "Value":{
       "Type":{ // The node id of the data type and not 22 (structure base data type node)
         "IdType":0,
         "Id":1986,
         "Namespace":4,
      }
       "Body":{
         "Body":{
           "Type":6,
           "X":47
         },
         "Body":{
           "Type":6,
           "Y":11
         }
       }
     }
   }
}

In short: What is the correct way, to encode data structured data of type "Coordinate" with JSON, such that a Client has knowledge about the structural appearance of the data and can directly decode the data (encoding must be reversible)? Preferrably, the metadata message aswell as the DataTypeDefinition attribute should not be read.

Thanks in advance and greetings,

Sebastian Schwinn

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
01/16/2023 - 12:55
sp_Permalink sp_Print

It appears the OPC UA PubSub Formatter is omitting the TypeId on the ExtensionObject,

I would expect to see:

{ "Coordinate":{"Value":{"Type":22,"Body":{"TypeId": { "Id":1986, "Namespace":4 }, "Body":{"X":47,"Y":11}}}}}

Avatar
Zbynek Zahradnik
Member
Members
Forum Posts: 62
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
3
01/16/2023 - 22:58
sp_Permalink sp_Print sp_EditHistory

Hello,

I am the author of the OPC UA PubSub Formatter.

 

Upon first look at this, I agree with Randy - the TypeId should be included as he suggested. I will check deeper, fix it if necessary, and then post an update and a notification here.

 

This is probably some regression, because I think I remember we used precisely this example for discussions regarding whether encoding Id or datatype Id should be used (and allowed for both).

Correction to OP: 22 does not stand for Structure datatype id. It stands for  built-in type ExtensionObject.

Regards

Avatar
Zbynek Zahradnik
Member
Members
Forum Posts: 62
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
4
01/17/2023 - 04:03
sp_Permalink sp_Print sp_EditHistory

The UA PubSub Formatter is now fixed.

It may take ClickOnce a day or two before it updates itself for you automatically, unless you force the update somehow. Verification: Click "About" in the right part of the window caption bar, the version should be 5.71.0.15 or later.

Regards

Avatar
Sebastian Schwinn
Member
Members
Forum Posts: 3
Member Since:
03/16/2020
sp_UserOfflineSmall Offline
5
02/14/2023 - 06:33
sp_Permalink sp_Print

Hello,

Sorry for the late answer! Many thanks for the clarifications and the fix. Works like a charm.

Best regards,

Sebastian Schwinn

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 17
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1349
Posts: 4579