ryusoup - 2023-10-04

Hello,
I am trying to implement a FB to make JSON formatted WSTRING type message using JSON Utilities 1.9.0.0 included in the IIoT library.

In my case, I want to set some objects or arrays and set values to them later.
But when I wrote as the sample below,

// init builder
builder(pJsonData:=pJsonData, diRootObj=>diRootObj);

// set the 1st key to root
diKey1 := builder.SetKeyWithArray(wsKey:="key1", diParentIndex:=diRootObj, eError=>eError);

// set a value to the 1st key
wsValue:="value01";
builder.SetValue(Value:=wsValue, diParentIndex:=diKey1, eError=>eError);

// set the 2nd key to root
diKey2 := builder.SetKeyWithArray(wsKey:="key2", diParentIndex:=diRootObj, eError=>eError);

// set a value to the 2nd key
wsValue:="value02";
builder.SetValue(Value:=wsValue, diParentIndex:=diKey2, eError=>eError);

// set a value to the 1st key again
wsValue:="value03";
builder.SetValue(Value:=wsValue, diParentIndex:=diKey1, eError=>eError);

// set a value to the 2nd key again
wsValue:="value04";
builder.SetValue(Value:=wsValue, diParentIndex:=diKey2, eError=>eError);

// write build result
writer(xExecute:=TRUE, pwData:=ADR(wsResult), udiSize:=SIZEOF(wsResult), xAsyncMode:=FALSE, jsonData:=pJsonData^);

the result was:

{
   "key1": 
     ["value01"],
   "key2": 
     ["value02", "value03", "value04"]
}

while my expection was:

{
  "key1": 
    ["value01", "value03"],
  "key2": 
    ["value02", "value04"]
}

Inspecting pJsonData^, JSONData itself seems to be ok, so I believe the issue is something caused by the writer FB.
Does anyone know how to fix it?

Thanks,