Closed qifuren1985 closed 7 years ago
The |
operator is supported. .[0]
is an array operation, so .[0] | keys
requires that the input object is an array containing objects. The following input works with .[0] | keys
:
[{"name": "obj1"}, {"name": "obj2"}]
If input json is big array, it will fail.
for example, type this code in chrome console, it will generate a big array, and copy to clipboard.
function gen_data() { var ret = []; for(var i=0; i < 10000; i++) { ret.push({"name": i , "kk": i * 2}) } return ret; } copy(JSON.stringify(gen_data()));
if we type: .length, it will return 10000 if we type: .[0] | keys, it will fail.
Yes, it fails, but not for that reason. That is failing due to a limitation of the size of the command line argument for jq
, which is being executed via child_process
.
For reference, this is the stack trace:
Editor.js:203 Error: spawn E2BIG
at exports._errnoException (util.js:1026:11)
at ChildProcess.spawn (internal/child_process.js:313:11)
at exports.spawn (child_process.js:392:9)
at Object.exports.execFile (child_process.js:155:15)
at Object.module.(anonymous function) [as execFile] (ELECTRON_ASAR.js:200:20)
at Object.exports.exec (child_process.js:115:18)
at Object.childProcess.(anonymous function) [as exec] (ELECTRON_ASAR.js:685:22)
at /Users/wells/src/JSON-Splora/node_modules/node-jq/lib/exec.js:21:29
at exec (/Users/wells/src/JSON-Splora/node_modules/node-jq/lib/exec.js:20:10)
at /Users/wells/src/JSON-Splora/node_modules/node-jq/lib/jq.js:39:241
http://stackoverflow.com/questions/36251711/node-child-process-throwing-e2big
So if input json is too big, we need pass it to node-jq from a temp file.
@qifuren1985 Interesting idea. Let's open this bug as a separate issue.
in jq, it support | operator, but it does not supported in JSON-Splora.
for example: jq '.[0] | keys' orders.json