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

Should jo import a child JSON from a file? #43

Closed
colrichie opened this issue Sep 20, 2016 · 4 comments
Closed

Should jo import a child JSON from a file? #43

colrichie opened this issue Sep 20, 2016 · 4 comments

Comments

@colrichie
Copy link

When I want to get a nested JSON, the jo(1) manual suggests to me like this

$ jo obj=$(ls | jo -a)

It means that jo gets keys and values of objects from the argument space.

But that has some problems.

  • It's impossible to generate a JSON the size of which is over than ARG_MAX.
  • jo has to refuse to accept single backslash (single doublequotation neither) without escaping to prevent command injection. So jo can't accept Unicode Escape Sequence strings (e.g. \u1234)

I think file can solve both the problems.

$ ls | jo -a > child.json
$ jo obj:=child.json

(":=" is a sample operator symbol for importing a child JSON from a file)

What do you think?

@jpmens
Copy link
Owner

jpmens commented Sep 20, 2016

Good idea. Now for somebody to implement this. 😄

@jpmens
Copy link
Owner

jpmens commented Sep 20, 2016

@richmikan Could you test this to see if it behaves like it should? :-)

@colrichie
Copy link
Author

colrichie commented Sep 20, 2016

Thanks for your quick improving. I also tried to use it immediately.

$ echo '["a","\u0020","b"]' > child.json
$ jo obj:=a.json
{"obj":["a"," ","b"]}
$ 

That's a great progress!
And I think jo will get greater if you add an option for passing through or converting Unicode escape sequence characters.

$ printf 'a\n\u0020\nb\n' | jo -a --some-option
["a","\u0020","b"]

Or

$ printf 'a\n\u0020\nb\n' | jo -a --some-option
["a"," ","b"]

@jpmens
Copy link
Owner

jpmens commented Sep 20, 2016

I would accept a pull-request for Unicode escape sequences.
Closing this now; thanks for your idea.

@jpmens jpmens closed this as completed Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants