Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Only include certain attributes #1

Open
rejeep opened this issue Mar 12, 2014 · 2 comments
Open

Feature request: Only include certain attributes #1

rejeep opened this issue Mar 12, 2014 · 2 comments

Comments

@rejeep
Copy link

rejeep commented Mar 12, 2014

Hello mr. Bjorn.

It's not in my nature to ask other people for favors (unless sexual), but I'm too lazy in this case.

I would like an option that works similar to transformers. The option takes one or more arguments and will for each JSON line, only include attributes that are specified as arguments to the option. For example:

{"one": "lorem", "two": "ipsum",     "three": "dolor"}
{"one": "amet",  "two": "consequat", "three": "tortor"}
{"one": "quis",  "two": "fermentum", "three": "magna"}

Running this:

$ cat ABOVE-FILE | jku --some-option one three

Would produce this:

{"one": "lorem", "three": "dolor"}
{"one": "amet",  "three": "tortor"}
{"one": "quis",  "three": "magna"}

Could you please implement this for me sugar?

@bjorne
Copy link
Owner

bjorne commented Mar 12, 2014

You mean you don't like writing this?

$ cat ABOVE-FILE | jku -t 'Object.keys(_).filter(function(k) { return ["one", "three"].indexOf(k) != -1 }).reduce(function(m,k) { m[k] = _[k]; return m; }, {})'

I like the idea!

@rejeep
Copy link
Author

rejeep commented Mar 12, 2014

Yes! If you are working with large Json files, the first step could be to only select the attributes you want and save that to a new file. That would be consecutive operations a lot faster.

It would be neat if it was a little more complex that what you do above so that you could do this for nested expressions, for example:

$ cat SOME-FILE | jku --some-option one three names:names.people[0].name

There are most likely other complex situations that could be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants