Complex data structures json

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
3 posts • Page 1 of 1
n.kuehl
Posts: 28
Joined: Mon Mar 18, 2019 9:35 am

Complex data structures json

Post by n.kuehl »

Hello,

i want to export some data and use the json-Format. But it is returning an empty json-object.

mapping data = makeMapping(makeTime(2020,1,1), makeMapping("dp1.value", 596.9,"dp2.value", 915.9),
makeTime(2020,1,1,1), makeMapping("dp1.value", 984.5,"dp2.value", 564.5));
DebugN(data,jsonEncode(data));

Result:
WCCOAui2:[mapping 2 items
WCCOAui2:2020.01.01 00:00:00.000000000 : mapping 2 items
WCCOAui2: "dp2.value" : 915.9
WCCOAui2: "dp1.value" : 596.9
WCCOAui2:2020.01.01 01:00:00.000000000 : mapping 2 items
WCCOAui2: "dp2.value" : 564.5
WCCOAui2: "dp1.value" : 984.5
WCCOAui2:]["{}"]

Is this a bug or not a feature?

ozangor
Posts: 44
Joined: Thu Sep 22, 2011 2:57 pm

Re: Complex data structures json

Post by ozangor »

Hi there,

The issue seems to be, you are trying to use time objects as keys in json. You can use timestamp keys by casting the time to a string.

Code: Select all

mapping data = makeMapping((string)makeTime(2020,1,1), makeMapping("dp1.value", 596.9,"dp2.value", 915.9),
                             (string)makeTime(2020,1,1,1), makeMapping("dp1.value", 984.5,"dp2.value", 564.5));
  DebugN(data, jsonEncode(data));

Code: Select all

WCCOAui2:[mapping 2 items
WCCOAui2:   "2020.01.01 00:00:00.000" : mapping 2 items
WCCOAui2:	   "dp2.value" : 915.9
WCCOAui2:	   "dp1.value" : 596.9
WCCOAui2:   "2020.01.01 01:00:00.000" : mapping 2 items
WCCOAui2:	   "dp2.value" : 564.5
WCCOAui2:	   "dp1.value" : 984.5
WCCOAui2:]["{\"2020.01.01 00:00:00.000\":{\"dp1.value\":596.9,\"dp2.value\":915.9},\"2020.01.01 01:00:00.000\":{\"dp1.value\":984.5,\"dp2.value\":564.5}}"]

n.kuehl
Posts: 28
Joined: Mon Mar 18, 2019 9:35 am

Re: Complex data structures json

Post by n.kuehl »

Thanks a lot!
But for me this is more of a bug, because then I have to go through the entire data structure again. For etm it is surely very easy to fix this in the stdlib.

Post Reply
3 posts • Page 1 of 1