Question Soufiane Amroun · Sep 22, 2017

browse sql record

Hi , World

this is i field in my global:

{"profile_id":"9XOzzcI8NfSUjxAhEt0cTLRejwmp6HPi","biometrics":[{"timestamp":"2017-05-17T13:45:40","utc_offset":"+02:00","resting_heartrate":120.0,"spo2":98.0,"activity_id":"591c540aac8f295479ee14ce"}]}

for information: it's respective key is "peyload"

my question is :

I want to extract the timestamps value , and the profile_id value , how can i do?

thank's

Comments

Robert Cemper · Sep 22, 2017

assuming variable payload holds your content of "payload"

set profileId=$piece($piece(payload,"profile_id"":""",2),""",")

set timestamp=$piece($piece(payload,"timestamp"":""",2),""",")

0
Eduard Lebedyuk · Sep 22, 2017

Assuming  you're on 2016.2+:

set payload = "{""profile_id"":""9XOzzcI8NfSUjxAhEt0cTLRejwmp6HPi"",""biometrics"":[{""timestamp"":""2017-05-17T13:45:40"",""utc_offset"":""+02:00"",""resting_heartrate"":120.0,""spo2"":98.0,""activity_id"":""591c540aac8f295479ee14ce""}]}"
set obj = {}.%FromJSON(payload)
write obj."profile_id"
>9XOzzcI8NfSUjxAhEt0cTLRejwmp6HPi
write obj.biometrics.%Get(0).timestamp
>2017-05-17T13:45:40
0
Tiago Ribeiro · Sep 22, 2017

Assuming you're on 2013.1+:

set data = "{""profile_id"":""9XOzzcI8NfSUjxAhEt0cTLRejwmp6HPi"",""biometrics"":[{""timestamp"":""2017-05-17T13:45:40"",""utc_offset"":""+02:00"",""resting_heartrate"":120.0,""spo2"":98.0,""activity_id"":""591c540aac8f295479ee14ce""}]}"

do ##class(%ZEN.Auxiliary.jsonProvider).%ParseJSON(data,,.object)
write object."profile_id"
write object.biometrics.GetAt(1).timestamp

0