Skip to content

A function to check if string is JSON object

License

Notifications You must be signed in to change notification settings

rcemper/function-ISJSON

Repository files navigation

function to check string if JSON object

It's also an example of a customized SystemFunction extension (ZZISJSON) in Caché & IRIS
This time it is to be included in %ZLANGF00.mac

A JSON string is mostly imported from file or over REST
You rely on a clean and compatible structure. This is the check.

required: ZPretty.mac
available here https://github.com/rcemper/ZPretty-1 or included in this repo in ZZISJSON.xml for classic install or on OEX: https://openexchange.intersystems.com/package/ZPretty
or

USER>ZPM "install pretty-json"

demo

USER>set jsn="{'Name':'Li,Robert K.','SSN':'672-92-9664','DOB':'1975-01-12','Home':{'Street':'986 Washington Blvd','City':'Boston','State':'PA','Zip':'95802'},'Office':{'Street':'6012 First Place','City':'Reston','State':'MT','Zip':'77739'},'Spouse':{'Name':'Avery,Zelda H.','SSN':'323-13-7437','DOB':'1943-03-27','Home':{'Street':'196 Main Drive','City':'Youngstown','State':'WY','Zip':'53229'},'Office':{'Street':'4056 Franklin Court','City':'Bensonhurst','State':'IA','Zip':'27688'},'FavoriteColors':['Black'],'Age':77},'Age':45,'Title':'Associate Marketing Manager','Salary':10421}"
USER>ZWRITE jsn  
jsn="{'Name':'Li,Robert K.','SSN':'672-92-9664','DOB':'1975-01-12','Home':{'Street':'986 Washington Blvd','City':'Boston','State':'PA','Zip':'95802'},'Office':{'Street':'6012 First Place','City':'Reston','State':'MT','Zip':'77739'},'Spouse':{'Name':'Avery,Zelda H.','SSN':'323-13-7437','DOB':'1943-03-27','Home':{'Street':'196 Main Drive','City':'Youngstown','State':'WY','Zip':'53229'},'Office':{'Street':'4056 Franklin Court','City':'Bensonhurst','State':'IA','Zip':'27688'},'FavoriteColors':['Black'],'Age':77},'Age':45,'Title':'Associate Marketing Manager','Salary':10421}"

USER>if $ZZISJSON(jsn) write "OK"   
OK

USER>set is(1)=$ZZISJSON(jsn),is(2)=$ZZISJSON(jsn_",home:") zwrite is   
is(1)=1
is(2)=0

Article in DC

About

A function to check if string is JSON object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •