# Best way to get JSON config in perspective

**URL:** <https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 17, 2021, 7:36pm UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714 "2021-04-17T19:36:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [April 17, 2021, 7:36pm UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/1 "2021-04-17T19:36:47Z")

</div>

I have a need to store between 10-50 different JSON objects (approx. 5000 characters in plain text)

Currently they are stored in a database, and joined against the data they are relevant too. This is fine except when I query the data I am ending up repeating the JSON for every record and the dataset becomes quite large.

I know that I can store it as dictionaries in a project script, a web dev text resource, a general file on the gateway, and I’m sure there are more options.

However I’m curious which version would be the most optimal… the text resource sounds good, but to access it I would have to make an HTTP call as opposed to just opening it as a file.

Any ideas are welcome!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 17, 2021, 10:13pm UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/2 "2021-04-17T22:13:46Z")

</div>

Text resource would be the slowest as you’ll then be reading it from disk rather than from memory.  
Stroing as array(s) of dictionaries would be the fastest I think. It’s fun making this globally available though, as I discovered. There’s an independent scope for designer, tags, gateway scripts… Maybe more

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [April 18, 2021, 12:09am UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/3 "2021-04-18T00:09:18Z")

</div>

So would you store them as a text resource, and then have a gateway script that stores them as globals every 60 seconds or so?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 18, 2021, 12:43am UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/4 "2021-04-18T00:43:59Z")

</div>

I would cache them in a dictionary nested in the dictionary from system.util.getGlobals(). Update in place on demand. In a script named `jsonCache`, you can reliably set that up with something like this:

```auto
c = system.util.getGlobals().setdefault('jsonCache', {})

```

Then, wherever you need it, just use `jsonCache.c.get('someKey')`. If it returns `None`, retrieve/decode it from permanent storage, and assign back to the cache for future users: `jsonCache.c['someKey'] = json`. Jython dictionaries are thread-safe, so parallel updaters won’t break anything.

If the retrieval is sufficiently generic for any given key, you could make that generic with something like this (also in `jsonCache`):

```auto
def get(key):
    json = c.get(key)
    if json is not None:
        return json
    # Retrieve from permanent storage
    # into "json".
    c[key] = json
    return json

```

Then users only need `jsonCache.get('someKey')`.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 18, 2021, 2:07am UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/5 "2021-04-18T02:07:41Z")

</div>

> [@pturmel](#):
>
> jsonCache.get('someKey')

I keep reading that as "get smokey" 😅

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [April 18, 2021, 2:34am UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/6 "2021-04-18T02:34:14Z")

</div>

It’s managed with the rest of the project through git, any ideas on how you’d manage a diff between the one existing in the cache vs and potential new ones? That’s kind’ve where I was thinking about a timer script to verify if it’s different.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 18, 2021, 1:12pm UTC](https://forum.inductiveautomation.com/t/best-way-to-get-json-config-in-perspective/45714/7 "2021-04-18T13:12:50Z")

</div>

I wouldn’t bother with diff. Just cache the file’s stat() items (mod time, filesize, inode, etc) and reload on change. If the content is still equal, it won’t hurt anything to just replace the dictionary entry unconditionally. If some event happens where you know there is a change, you can pre-emptively `del` that entry to force a reload earlier than a timed check. (Do not check stat() on every lookup–that’ll kill your cache performance.)
