move repo and archive
The similarity between JSON objects + arrays and Globals in IRIS or Caché is evident.
With small and medium size JSON objects navigation across %Dynamic Objects is comfortable.
But with large and/or deep cascaded objects it becomes a challenge.
The presented tool offers 3 variants
UESR>read str {"id":306904,"last_star_ts":0,"completion_day_level":{},"global_score":0,"local_score":0,"stars":0,"name":"name_1"} USER>set jsn={}.%FromJSON(str) USER>write ##class(rcc.jstog).toglobal(jsn,"^jsn") 1 USER>zwrite ^jsn ^jsn("global_score")=0 ^jsn("id")=306904 ^jsn("last_star_ts")=0 ^jsn("local_score")=0 ^jsn("name")="name_1" ^jsn("stars")=0
USER>zzjson jsn
{
"id":306904,
"last_star_ts":0,
"completion_day_level":{
},
"global_score":0,
"local_score":0,
"stars":0,
"name":"name_1"
}
USER>
from an already existing Stream it’s like this
USER>write ##class(rcc.jstog).stream(jsonstream,"^jsstr")
1
and from file it is this method:
USER>set filename="/opt/irisbuild/src/data/big6.json"
USER>write ##class(rcc.jstog).file(filename) ; using default global ^json
1
USER>
Make sure you have git and Docker desktop installed.
Clone/git pull the repo into any local directory
git https://github.com/rcemper/JSONfile-to-Global.git
Run the IRIS container with your project:
docker-compose up -d --build
log in to command line or use Webterminal
docker-compose exec iris iris session iris
2 test files are available
USER>......< your choice > ....."
USER>kill ^json ; using default global ^json
USER>write ##class(rcc.jstog).file(filename)
1
USER ZWRITE ^json