Live data from Hacker News

Jo – a shell command to create JSON (2016)

jpmens.net

21–30 of 100 posts

Re: Jo – a shell command to create JSON (2016)

#21

This is cool. In the spirit of "do one thing well", I'd so rather use this to construct JSON payloads to curl requests than the curl project's own "json part" proposal[1] under consideration. [1]: https://github.com/curl/curl/wiki/JSON#--jp-part

Agree, I was surprised that the cURL feature was considered as it seems to go against the "Do One Thing" and composability points of the UNIX philosophy.

Re: Jo – a shell command to create JSON (2016)

#22
post #19

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers. I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string. This sounds like the Norway Problem waiting to happen.

then use -s :

        jo -- -s opaque_id=001979
        {"opaque_id":"001979"}

Re: Jo – a shell command to create JSON (2016)

#24
post #19

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers. I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string. This sounds like the Norway Problem waiting to happen.

It looks like you can specify the value type per property, for those cases where it matters.

Re: Jo – a shell command to create JSON (2016)

#25
post #19

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers. I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string. This sounds like the Norway Problem waiting to happen.

It is reminiscent of a feature in YAML that has bitten people.

But, clearly there is a use-case for producing json with integer, null, and boolean values.

Re: Jo – a shell command to create JSON (2016)

#26
post #21

This is cool. In the spirit of "do one thing well", I'd so rather use this to construct JSON payloads to curl requests than the curl project's own "json part" proposal[1] under consideration. [1]: https://github.com/curl/curl/wiki/JSON#--jp-part

Agree, I was surprised that the cURL feature was considered as it seems to go against the "Do One Thing" and composability points of the UNIX philosophy.

Curl does like 100 "things" already by that standard. The Unix philosophy doesn't have to be reductionist.

Curl does do one thing: make network requests. This feature is making it easier to make network requests, i.e. it makes it better at doing the one thing that it does.

Re: Jo – a shell command to create JSON (2016)

#27
post #19

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers. I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string. This sounds like the Norway Problem waiting to happen.

It is reminiscent of a feature in YAML that has bitten people. But, clearly there is a use-case for producing json with integer, null, and boolean values.

Of course there is, but it should be done explicitly - i.e. treat as a string by default but use -n if it's a number rather than having a guess.

Re: Jo – a shell command to create JSON (2016)

#28
post #22
post #19

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers. I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string. This sounds like the Norway Problem waiting to happen.

then use -s : jo -- -s opaque_id=001979 {"opaque_id":"001979"}

jo opaque_id=$(command used in prod that returns digits + letters for three months and everything works just fine and then suddenly at 3am on a Sunday it returns 1979 and breaks everything)

Avoid using this command in prod.

Re: Jo – a shell command to create JSON (2016)

#29
I remember that when I worked at Google about a decade ago, there was this common saying:

"If the first version of your shell script is more than five lines long, you should have written it in Python."

I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or Javascript, it would have been far more obvious what the resulting output would have been, considering that those languages already use {} for objects and [] for lists.

For example, take this example:

    jo -p name=JP object=$(jo fruit=Orange point=$(jo x=10 y=20) number=17) sunday=false
In Python you would write it like this:

    json.dumps({"name": "JP", "object": {"fruit": "Orange", "point": {"x": 10, "y": 20}, "number": 17}, "sunday": False})
Only a bit more code, but at least it won't suffer from the Norway problem. Even though Python isn't the fastest language out there, it's likely still faster than the shell command above. There is no need to construct a fork bomb just to generate some JSON.

Re: Jo – a shell command to create JSON (2016)

#30

The more I work with JSON, the more I crave some kind of dedicated json editor to easily visualize and manipulate json objects, and to serialize / deserialize strings. This is especially the case with truly massive JSON objects with multiple layers of nesting. Anyway, cool tool that makes one part of the process of whipping up JSON a little less painful

I built a JSON editor for Android a while back as part of a tool for kicking off AWS Lambda functions. I was planning on pulling the JSON editor to it's own reusable package, but lost momentum. I imagine it could be useful in many sorts of apps that use JSON.

https://play.google.com/store/apps/details?id=com.alexsci.an...

https://github.com/ralexander-phi/android-aws-lambda-runner

Post reply on HN