jpmens / jo

JSON output from a shell
http://jpmens.net/2016/03/05/a-shell-command-to-create-json-jo/
Other
4.62k stars 153 forks source link

String coercion creates empty string from "null" value #210

Closed h4l closed 2 days ago

h4l commented 4 days ago

The -s string coercion flag results in an empty string when the value is null:

jo -- -s foo=null
{"foo":""}

$ jo -v
jo 1.9

I would expect the result to be {"foo":"null"}.

jpmens commented 4 days ago

I don't see why you would expect that to happen; I wouldn't.

h4l commented 3 days ago

Maybe I'm misunderstanding the intention of the -s flag, I assumed it would force the value to be treated as a string. Is there a way to produce the string "null" with jo?

gromgit commented 2 days ago

Yes, escape the first letter with a backslash:

$ jo -- -s foo=\\null
{"foo":"null"}

Note that the null-to-"" coercion is explicitly documented in the man page.

h4l commented 2 days ago

OK, thank you.