reading JSON file
Hi Guys,
I'm using the below so I can put JSON file in an object and read each property:
d ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(JSONString3,,.list)
S Job= list.jobGUID
but because the JSON starts and ends with [ ] my list is empty, and I had to remove them to get a good list.
So is there a way that I can handle this which having me removing those brackets each time, because I thought %ConvertJSONToObject to be able to handle this anyway?
FYI I'm running Ensemble 2014
[{"routeGuid":"531318d8-9967-445a-ae42-14e04244e0fb","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-20T23:04:51.159Z","myProperty":0,"callbackHost":"https://vibra-api-dev.azurewebsites.net/api/sensors/vibration","collectionQuantity":1,"collectionInterval":0,"collectionTimeout":28140,"locationName":"Test Plant 1","locationGuid":"286c2dac-597d-41b0-8f6e-55f19fce9a9e","sensors":[{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"0b955ee7-9a54-4b13-9af1-7019721faeab","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000}]
Thanks
From your JSON-String, someone stripped off two chars at the end: "}]"
So if you add those chars, everything will be OK
d ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(JSONString3_"}]",,.list) w list.GetAt(1).sensors.GetAt(1).jobGUID --> 0b955ee7-9a54-4b13-9af1-7019721faeab
what I sent is just a part of the full JSON as an example so it's not because it's missing part of it here is the full string, where I had to remove the brackets from beginning and end
read json <now, Cntrl-V here the above string, press enter>, then
w ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(json,,.list1) --> 1 w list1 --> 42@%Library.ListOfObjects w list1.GetAt(1).sensors.GetAt(1).jobGUID --> 0b955ee7-9a54-4b13-9af1-7019721faeab
where is the problem?
Ok I see, I did add the GetAt(1).
Thanks Julius
To get all the jobGUIDs you need two loops:
f i=1:1:list1.Size f j=1:1:list1.GetAt(i).sensors.Size w list1.GetAt(i).sensors.GetAt(j).jobGUID,! 0b955ee7-9a54-4b13-9af1-7019721faeab 8f9e85ab-31e7-4835-8969-6d72d142a2f1 68cea9d3-54cd-43f2-ae37-aaf47ed43e6b 7602764e-8951-451f-9653-ceb84834a1a6 88d2e472-a1e4-40b3-a108-f2d32a2023e5 116f2ac6-da5f-46da-a7c7-92d9eaf98c89 a878e527-f519-4aaa-bf5d-0d65f72de119 be570b14-0555-4b86-ab9f-e37c40c79216 3a13e243-d6ed-4788-98b2-52e9213bee00 54969869-c4f6-43f6-a74a-2a67f9a73fc5 700af7d3-77b3-4a84-ba11-ea49602d6558 18dc3370-c291-468b-af1f-0361d95bb02c 35d0d2e7-1199-4c18-8941-4fff6dbdba1f 8044560c-94d2-4da7-87f5-07328d9e62c1 b636a2f5-d35f-4c82-9646-e09572336e23 9c9a4bf4-e8af-4b8d-9de2-a99cdff150ed a576d235-6eb6-4312-a1ff-7b1f767b88ce 654cf21e-daad-4a11-b676-86a7bc8a3360 2be4efc8-6616-4bff-87ba-30fe388a1b34 a5374d6c-311c-44d0-8d06-3a31f33dd3a8 955529c5-36be-4f3e-b768-0e3b377804a7 60a7cdb0-499e-4d02-b4d3-06ee58e40481 e84eda78-1491-49af-9e34-d647e817a251 9bcd5fe6-6f05-4482-ad78-612f35c60b41
Hi Julius,
Thanks
Hi Julius,
Pls ignore my last message, I was just trying to attach a file to my message but didn't work.
Thanks
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue