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?
Complex data structures json
Search
Re: Complex data structures json
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.
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}}"]Re: Complex data structures json
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.
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.