Comments (10)
@radostyle For usage questions, please check out Stack Overflow: http://stackoverflow.com/questions/tagged/jq
Also, remember to read the manual first! It has nice sample programs you can use. http://stedolan.github.io/jq/manual/#containselement
As per your example, a sample working program would be select(.hello | contains("hi"))
from jq.
This is a slippery slope towards full regexp support, which actually I think would be a good idea. Easy to add via RE2 or PCRE.
from jq.
Yeah, this is something you just can't do in jq at the moment. I'll should be fairly straightforward to add a builtin function that checks for substrings.
Later on, I'm definitely considering shoving in PCRE. I want to be a bit careful about dependencies, so I might end up using PCRE with some dlopen
trickery so that the rest of jq still runs if the PCRE library is unavailable at runtime. That might be messy, though.
from jq.
I'm working on this. I'm currently implementing a more general subset operator.
# string b is a subset of string a if string b is wholely contained in string a
"foobar" =: "foo" -> true
"foobar" =: "baz" -> false
# arrays are treated like ordered lists, not as sets. the subset operator ensures
# that the first array contains all the elements in the second array in the same
# order consecutively. elements are compared using regular equality.
[1,2,3,4] =: [2,3] -> true
[1,2,3,4] =: [3,2] -> false
[1,{foo: 12, bar: 13},3,4] =: [1,{foo: 12, bar:13}] -> true
[1,{foo: 12, bar: 13},3,4] =: [1,{foo: 12}] -> false
# An object b is a subset of object a if for every key in b there is a key in a
# such that if the values are both objects the object from b is a subset of the
# object from a, or if the values are any other type they are equal.
{foo: 12, bar:13} =: {foo: 12} -> true
{foo:12} =: {bar:13} -> false
{foo: {bar: 12, baz: 13}, blap: [1,2,3]} =: {foo: {bar: 12}, blap: [1,2,3]} -> true
{foo: {bar: 12, baz: 13}, blap: [1,2,3]} =: {foo: {bar: 12}, blap: [1,2]} -> false
Thoughts on this, before I pull request the code?
EDIT: fixed one of the examples.
from jq.
I'd swap the arguments around and spell the operator "in", this syntax is a little cryptic.
I think arrays-as-sets might be more useful, I don't often find myself doing subsequence searches in an array.
When comparing objects, I'm not sure I follow the logic behind recursing into other objects but not arrays. Although I'm not sure any alternative would seem more natural.
If you're implementing a general "containment" operator, it might be nice to support "string" is-a-subset-of "object" to mean "does the object have this key".
Looks cool!
from jq.
Fixed by #36. This can be closed.
from jq.
How do you use this feature?
$ echo '{ "hello":"hi"} ' | jq 'select(.hello contains( "hi"))'
error: syntax error, unexpected IDENT
select(.hello contains( "hi")) 1 compile error
$ echo '{ "hello":"hi"} ' | jq 'select(.hello contains "hi")'
error: syntax error, unexpected IDENT
select(.hello contains "hi") 1 compile error
from jq.
Thank you Santiago. I did not realize you had to use the pipe operator '|'
as a test. I did read the manual but in the manual there is no example
with the pipe operator. Perhaps I should add one?
On Tue, Jun 23, 2015 at 1:43 PM, Santiago Lapresta <[email protected]
wrote:
@radostyle https://github.com/radostyle For usage questions, please
check out Stack Overflow: http://stackoverflow.com/questions/tagged/jqAlso, remember to read the manual first! It has nice sample programs you
can use. http://stedolan.github.io/jq/manual/#containselementAs per your example, a sample working program would be select(.hello |
contains("hi"))—
Reply to this email directly or view it on GitHub
#33 (comment).
from jq.
@radostyle The manual does have a short section about the pipe operator, although, ironically, I can't link you to it since its name is just the pipe character... still, it should be strongly emphasised in the documentation, given that it is perhaps the most essential part of the language, and it certainly is not right now.
Any documentation changes that make jq easier to use are welcome, and heavily encouraged in fact! The documentation is over at docs/content/3.manual/manual.yml
; some basic and probably outdated information on how to run the documentation server locally can be found here. Serve yourself!
from jq.
from jq.
Related Issues (20)
- Regular expression alternation (|) used with quantifier (* or +) returns inconsistent results when first alternative is able to match an empty string HOT 3
- Create Multi Smaller Files From a Big Json File HOT 5
- Add the Symbolic Binding Operator ("as") to the operator priority table HOT 1
- Including and importing module with importing JSON crashes jq
- The code example for trim ltrim and rtrim from the manual do not work HOT 2
- Incorrect `Invalid path expression` in destructuring expressions
- 1.7.1 dumps core on Cygwin, trying to find the input filename to print an error message HOT 5
- jq --raw modes, --binary and newlines
- Request for snap maintenance HOT 11
- strptime month does not match input HOT 2
- Using unique or unique_by in a filter causes subsequent (after comma ,) filter inputs to be replaced with its output HOT 5
- Docker images lack `latest` tag HOT 2
- modulemeta failure when module location is found by "search"
- oss-fuzz/issues/detail?id=68056
- Unexpected env builtin behaviour HOT 5
- Undefined behaviour in use of <ctype.h> functions
- Add builtin to output to file HOT 5
- Сreating multilevel json with the jq utility in a bash script HOT 2
- More helpful message when passing a JSON-SEQ file without the `--seq` flag HOT 1
- `JV_PRINTF_LIKE` macros in `jv.h` missing fallback definition HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.