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
Comments
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
JSON
[{"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},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"8f9e85ab-31e7-4835-8969-6d72d142a2f1","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"68cea9d3-54cd-43f2-ae37-aaf47ed43e6b","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"7602764e-8951-451f-9653-ceb84834a1a6","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000}]},{"routeGuid":"8c9d66f8-b6ff-4eba-9529-c4aec6443751","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-20T15: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":"88d2e472-a1e4-40b3-a108-f2d32a2023e5","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"116f2ac6-da5f-46da-a7c7-92d9eaf98c89","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"a878e527-f519-4aaa-bf5d-0d65f72de119","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"be570b14-0555-4b86-ab9f-e37c40c79216","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000}]},{"routeGuid":"2c661016-ebbd-4f26-b8e0-1ef63dc0b473","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-20T07: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":"3a13e243-d6ed-4788-98b2-52e9213bee00","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"54969869-c4f6-43f6-a74a-2a67f9a73fc5","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"700af7d3-77b3-4a84-ba11-ea49602d6558","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"18dc3370-c291-468b-af1f-0361d95bb02c","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000}]},{"routeGuid":"8e11ea63-be68-4283-91a3-6586eb1172b3","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-19T23: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":"35d0d2e7-1199-4c18-8941-4fff6dbdba1f","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"8044560c-94d2-4da7-87f5-07328d9e62c1","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"b636a2f5-d35f-4c82-9646-e09572336e23","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"9c9a4bf4-e8af-4b8d-9de2-a99cdff150ed","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000}]},{"routeGuid":"b8e5e096-c9bc-41c5-a1af-713301cb7545","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-19T15: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":"a576d235-6eb6-4312-a1ff-7b1f767b88ce","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"654cf21e-daad-4a11-b676-86a7bc8a3360","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"2be4efc8-6616-4bff-87ba-30fe388a1b34","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"a5374d6c-311c-44d0-8d06-3a31f33dd3a8","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000}]},{"routeGuid":"9ea2968a-8deb-480c-9591-ffa18760b87f","sensorType":"MEMS TRIAXIAL","startDateTime":"2022-05-21T07: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":"955529c5-36be-4f3e-b768-0e3b377804a7","sensorId":"001011","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"60a7cdb0-499e-4d02-b4d3-06ee58e40481","sensorId":"001001","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"e84eda78-1491-49af-9e34-d647e817a251","sensorId":"MY0087","sampleRate":5000,"numberOfSamples":30000},{"equipmentName":"TestAsset 1","equipmentGuid":"ca62ff12-37fe-47a3-a315-95a4c011d835","componentName":"TestMOTORComponent 1","componentGuid":"3a291bf6-1ffd-4e14-b265-4b973c7660df","jobGUID":"9bcd5fe6-6f05-4482-ad78-612f35c60b41","sensorId":"MY0088","sampleRate":5000,"numberOfSamples":30000}]}]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