json4shell
json4shell copied to clipboard
Wrap json-iterate output like array
Current json-iterate output:
echo '[1,2,3,4]'| ./json-iterate -j echo {}
{"returncode": 0, "stderr": "", "stdout": "1\n"}
{"returncode": 0, "stderr": "", "stdout": "2\n"}
{"returncode": 0, "stderr": "", "stdout": "3\n"}
{"returncode": 0, "stderr": "", "stdout": "4\n"}
Proposal:
echo '[1,2,3,4]'| ./json-iterate -j echo {}
[{"returncode": 0, "stderr": "", "stdout": "1\n"},
{"returncode": 0, "stderr": "", "stdout": "2\n"},
{"returncode": 0, "stderr": "", "stdout": "3\n"},
{"returncode": 0, "stderr": "", "stdout": "4\n"}]
I can do this, but it more about other idea - to accept such 'stacked json' as valid input. The problem is that if application terminates unexpectedly, in case of array, it will leave invalid json. Moreover, there is a lot of problems with normal 'grep-like' operations.
I really like to keep compatibility with current type of shell line-based processing.
I think whole thing is about input, not output - we should be able to take as valid input those things:
[ "1", "2", "3", ]
[ "1", "2",
"2", "3" ]
"1" "2" "3"
I see how tricky it's gonna be, but it's absolutely necessary to allow relaxed input - else it's gonna be very unfriendly to user, who gonna be forced to 'hacks' around pipe just to satisfy inputs.
Hm, your arguments convinced me. Okay then.
Leaving this issue open for future discussion, anyway.
Yep, I'll change output to full json (just need to find way how to generate output steady). I think, it's gonna be clear after I repeat my experiments with JSONStreams