Enriching messages with local static data #2374
-
Hi all, please forgive me if the answer is obvious, but I have spent three days bashing my head into the docs trying to understand the correct way to do this (and read all the discussions) and have run out of ideas. I'm trying to enrich messages with data stored in a JSON file (key->object reference data, basically). I can see that it's possible, if the JSON file were hosted somewhere, to use the Given that I have a medium-sized JSON file locally, what is the best/simplest way to enrich messages with data from that file? -- |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I got it "working" in what feels like a horrible way:
...but I am surely missing something about the idiomatic way to do this. If needs be I'll just pretend this file doesn't exist and not look in it... |
Beta Was this translation helpful? Give feedback.
-
Hey @lawrencejob 👋 Assuming that the "medium-sized JSON file" you have easily fits in memory in its entirety, then you can use a |
Beta Was this translation helpful? Give feedback.
Hey @lawrencejob 👋 Assuming that the "medium-sized JSON file" you have easily fits in memory in its entirety, then you can use a
mapping
processor where you have something likelet toc_colors = file(path:"path_to_the_json_file", no_cache:false).parse_json()
. If the file can change in time, you can setno_cache:true
, but that will be slow since it will read the file each time this processor is invoked. There are workarounds if you need to cache it for a certain period of time, like using an in-memory cache with somettl
. There's alsofile_rel()
if you wish to keep this mapping along with the json file in some separate folder.