Article
· Jan 30, 2023 2m read

JSONfile-to-Global #1

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

  • loading an already existing %Dyamic object or Array into a global of your choice
  • loading a %Stream containing a JSON object into a global of your choice
  • loading an external File containing a JSON object into a global of your choice

How to use it

USER>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 a file it is this method:


USER>set filename="/opt/irisbuild/src/data/demo.json"
USER>write ##class(rcc.jstog).file(filename)  ; using default gloabel ^jsom
1
USER>

File content:
 

Global content:

This might not look so spectacular.
But see and try the difference with a 6 MB sized JSON Object.

Video

GitHub

Discussion (1)1
Log in or sign up to continue

Hi Robert,

Your video is now on InterSystems Developers YouTube:

⏯ JSONfile to Global

https://www.youtube.com/embed/1DvCPMj6ph0
[This is an embedded link, but you cannot view embedded content directly on the site because you have declined the cookies necessary to access it. To view embedded content, you would need to accept all cookies in your Cookies Settings]

Thank you very much!