Open vaibhav101 opened 5 years ago
The output you're looking for isn't valid json, so it's not possible (and won't be) with jq.
@wtlangford, I suspect that @vaibhav101 means that in colorized output mode the parts @vaibhav101 highlighted with asterisks would actually be highlighted with color. I think that would be OK, because remember, colorized JSON output isn't valid JSON either :)
However, I don't really know how to implement something like this in a sensible way.
Hey @nicowilliams, you got it right. I want to highlight the matching portions of JSON.
If this feature does not exist, can you point me towards how to go about creating it?
Thanks!
@vaibhav101 it's... not easy. The problem is that jq is not just a .this[0].that
path expression language only -- it's a full-blown programming language, and while path expressions are essential to jq's nature, you can have programs that aren't path expressions, and you can have path expressions embedded in several subexpressions. So, when we're matching a path, that doesn't mean we're matching a path that the user wants highlighted -- the path matched might not even exist in the final output object.
Also, the jv
API used internally for representing parsed values doesn't currently have a way to say "hey, highlight this on output in colorized output mode". Changing this would be the first step, but then that would have to be integrated into the language somehow.
Assuming jv
support for highlighting, the next step would probably be to add a builtin function that takes a path expression and marks the matching values (if any) to be highlighted.
If you want to take a crack at this, my advice would be to start with this reading list, in this order:
jv
API wikiDon't be intimidated. That's a lot of stuff, though as programming languages go, it's pretty small.
Example
Input
Selector
Output
My use case is to create a Sublime Text plugin which selects the matching regions.
Thanks!