Feature request: JSON pre-processing #256
Replies: 4 comments
-
Yes! This is something I've been thinking about for a while actually. Though from the perspective of "nesting" queries rather than "preprocessing" them. Basically, you'd be able to create a child query from another query. Basically nesting them under each other. This would let you use both JSONata and JSONpath for different parts of the response. Does that sound like what you were looking for? |
Beta Was this translation helpful? Give feedback.
-
@marcusolsson Oh, I hadn't thought about it that way, but now that you mention it that would do what I want - I'd wrap all my field queries in one "group". I'm curious about how you'd implement this - in my mind the fields would go from being a flat list to a "tree", where the root and branches are groups. Something like this:
And then at runtime it'd traverse the tree, essentially flattening it to get the resulting fields, so you end up with just |
Beta Was this translation helpful? Give feedback.
-
Exactly! It would essentially just be an easier way to build the queries. You'd still need each query to return arrays of the same length. |
Beta Was this translation helpful? Give feedback.
-
Sounds good! I've started work on this on my fork at main...markspolakovs:marks/field-groups - currently I've only got the back-end (and it needs work), I'll submit a PR once it's ready. |
Beta Was this translation helpful? Give feedback.
-
Firstly, thanks for writing and maintaining this plugin! It's been really useful.
Often I've found myself writing nearly the same set of JSONPath/JSONata expressions for each field, with only minor differences. To take a trivial example, if I have an API that returns
{"array": [{}, {}, ...]}
, I need to prefix each field's query with$.array[*]
.It'd be useful if there was a way of applying a JSONPath/JSONata transformation to the complete response body before handing it off to the individual fields - in the above example this would involve a "global" expression of
$.array[*]
, and then each field could reference the array element individually.I'd be up for writing up a PR to implement this if you think it'd be useful (I've never worked on Grafana plugins before, but there's a first time for everything!).
Beta Was this translation helpful? Give feedback.
All reactions