Comments (12)
@shouze I'll check that tomorrow 🙂.
from jql.
@shouze just to clarify, you want a way to select the
nth
key of an object (eventually multiple keys by their index), correct?
Yes you're right! 💯
from jql.
@yamafaktory you're on 🔥 😄
Very nice and clear! Will replace my jq
use case by jql
with that new feature 💯
from jql.
@yamafaktory thanks a lot 🙇 , I comfirm that it works like a charm if I pipe this kind of filter on my (more complex thant my initial issue example) json payload: |[0]{[0]}|"0"
.
from jql.
I can run
jql -r '..[]|"key1"'
On this payload:
[
{
"key1": [
{
"subkey1": "value"
}
]
},
{
"key1": [
{
"subkey2": "value"
}
]
}
]
that produces the expected output, but this is not the same input, and in my case very useless as I haven't a deterministic value for the equivalent of this "key1" key.
from jql.
Hi @shouze , jql is not intended to be a full replacement of jq. The grammar / query syntax is definitely different.
from jql.
@yamafaktory yes of course, I was just wondering if I could achieve this payload processing with jql.
from jql.
@shouze I've checked and indeed this is definitely not something jql was designed for. I fully understand the intent there - though the original jq command you have posted is honestly something I'd not try to implement as it looks so unintuitive too me 👾.
Basically, we we'll need some kind of new feature / grammar definition to be able to select the first key of an object.
I'll think about wether or not this is something jql should provide/ benefit from or not. Furthermore, if true, I'll need to see how this new grammar rule should look like without breaking anything (and without all the pitfalls from jq https://github.com/stedolan/jq/wiki/How-to:-Avoid-Pitfalls).
from jql.
@yamafaktory thanks a lot for checking 🙏.
I was not sure but yes I've read the pest grammar file yesterday and it probably miss a reserved keyword or symbol to design whatever key. Could be *
or %
for example? Thus would allow to write ..[]|%
instead of ..[]|"key1"
and would solve the dynamic sibling.
I don't know how complicated it could be to implement this feature after extending the grammar, neither how intuitive and aligned with your jql
vision it is.
from jql.
@shouze just to clarify, you want a way to select the nth
key of an object (eventually multiple keys by their index), correct? Your example with a *
is not going to work if there are more than one:
[
{
"key1": [
{
"subkey1": "value"
}
]
},
{
"key2": [
{
"subkey2": "value"
}
],
"key3": "woot"
}
]
from jql.
@shouze hey there 🖖.
Just a little update. I'm working on a branch that will soon introduce a new feature. The core idea is to introduce a new syntax for property selection which is going to help with your issue.
Currently property selection is limited to picking some keys of a given object - in any arbitrary order - see https://github.com/yamafaktory/jql#property-selection.
I'll now make it possible to select properties by their indexes and even using a range. This of course introduce some more complexity since chaining filters e.g. must keep the ongoing transformation of the JSON data working.
Let's have an example which is indirectly covering your initial issue. This is a.json
:
{
"a": [
{
"key1": [
{
"subkey1": "value"
}
],
"key2": "a"
},
{
"key2": [
{
"subkey2": "value"
}
],
"key3": "b",
"key4": "c"
}
]
}
Now let's first go step by step in order to highlight how it's working (please don't mind the cargo run
here, that will be just jql
for you when released):
cargo run '."a"|{[0]}' a.json
[
{
"0": [
{
"subkey1": "value"
}
]
},
{
"0": [
{
"subkey2": "value"
}
]
}
]
As you can see the idea is to remap the properties' names to be indexes. This way it works for multiple ones and for ranges too. Next obvious step, filter by the index:
cargo run '."a"|{[0]}|"0"' a.json
[
[
{
"subkey1": "value"
}
],
[
{
"subkey2": "value"
}
]
]
Almost there! We just need another filter or the spread syntax to get rid of the nested arrays. Final one-liner:
cargo run '."a"|{[0]}|"0"|[0]' a.json
cargo run '.."a"|{[0]}|"0"' a.json
[
{
"subkey1": "value"
},
{
"subkey2": "value"
}
]
I already have a bunch of new tests but I'll need some other ones for some corner cases. I'll also need to update the documentation. I'll keep you updated 🛠️.
from jql.
@shouze I've just released a new version https://crates.io/crates/jql/3.0.0 (your own v3 - a.k.a. shouze
version). I should now work as expected - with the jql syntax of course!
Feel free to open a new issue if something doesn't work as expected 🙇♂️.
from jql.
Related Issues (20)
- jq incompatibility or bug? HOT 2
- Make `clap` an optional dependency when using jql as a library HOT 3
- Flattened/Minified json file cannot be parsed HOT 7
- Proposal: pre-compile selectors HOT 4
- index out of bounds panic in array_walker HOT 1
- Feature request: Make async-std an optional dependency
- Conditional filters HOT 14
- Sort keys of objects HOT 9
- Add binaries to releases HOT 4
- Syntax: Is it necessary to have quotes and dots as delimiters? HOT 2
- Cannot select or filter on lens-produced arrays HOT 4
- lens conjunction doesn't work HOT 1
- lens conjunction doesn't work
- Windows release artifact always fails to upload HOT 2
- jql 6.0.3 test failure HOT 5
- Migration guide for library users? HOT 3
- Windows release artifacts fail to upload since v5.1.3 HOT 2
- Evaluate Profile-Guided Optimization (PGO) and LLVM BOLT HOT 5
- Windows build always gets 'Empty group' in all cases but `.` (once again) HOT 6
- Option for validation HOT 4
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 jql.