Commit Graph
115 Commits
Author SHA1 Message Date
David Tolnay f98c2b375d Use https where possible
Conflicts:
	docs/content/2.download/default.yml
	docs/content/index/index.yml
	docs/default_manpage.md
	docs/templates/index.liquid
	docs/templates/shared/_header.liquid
2015-08-15 23:32:03 -05:00
Nicolas Williams 66f7ce5ac3 Make all global module paths absolute (fix #817)
This is part 1 of the fix for #817.  The next commit is part 2.
2015-08-13 09:18:44 -07:00
David Tolnay b9c340a211 Change homepage .com -> .io
The .com redirects to .io, but might as well have the
correct one to begin with.
2015-07-24 22:55:58 -07:00
David Tolnay 1e5e0c9fe2 Make jq.h usable from C++
Previously, with clang++:
jq.h:46:37: error: typedef redefinition with different
      types ('struct jq_util_input_state *' vs 'jq_util_input_state')

With g++:
jq.h:46:37: error: conflicting declaration
      ‘typedef struct jq_util_input_state* jq_util_input_state’

This typedef was added to libjq by commit 0d41447 which was
after the 1.4 release, so although it is a public API, this
is not a backcompat break because it has never been in a
release.

Specifying the "*" at all uses of jq_util_input_state is
slightly tedious, but jq_state already works that way, so at
least it will be consistent.
2015-07-04 15:08:01 -07:00
Nicolas Williams 6c89186437 Make --run-tests less verbose by default
Adding --debug-trace or --debug-dump-disasm before --run-tests now makes
it verbose.
2015-06-27 23:31:44 -05:00
Nicolas Williams 8aecf82bfe WriteFile() on WIN32 when stdout isatty (fix #824)
Use WriteFile() and bypass stdio IFF stdout isatty and we're on Windows.
2015-06-22 20:47:47 -05:00
Nicolas Williams 7811ef1e17 Fix #811: use CommandLineToArgvW() and _wfopen() 2015-06-19 18:54:44 -05:00
Nicolas Williams 292f2d3208 argv[] may not be UTF-8 (fix #811) 2015-06-18 21:31:22 -05:00
Nicolas Williams 24a5e5b1b1 Add --tab and -indent n options 2015-06-03 20:20:11 -05:00
Nicolas Williams 74ecb88935 Improve usage message 2015-05-29 15:35:30 -05:00
Nicolas Williams 33874eb513 Fixup --slurpfile/argile docs 2015-05-29 15:25:30 -05:00
Nicolas Williams 1de56bc5df Add --slurpfile 2015-05-29 14:24:33 -05:00
Nicolas Williams 8a79f1d0a3 Better handling of stdout errors 2015-05-29 11:50:08 -05:00
Nicolas Williams f4f5d8882d Fix --argfile memleak (fix #799 part 2) 2015-05-29 11:49:45 -05:00
Nicolas Williams 89c57f7936 Revert "Fix #705 (--argfile weirdness)"
This reverts commit 3d2ab93b11.
2015-05-29 10:38:08 -05:00
Nicolas Williams 6af7857ccd Revert "Better argfile fix (#705, fix #736)"
This reverts commit 4f8567476d.
2015-05-29 10:37:58 -05:00
Assaf Gordon a6460f4fe2 Report filename:line on runtime errors (fix #752)
With this patch, jq run-time errors printed to stderr will contain the
filename and line of the offending input.

But note that the JSON text parser does (yet) print the input filename
on parse error.  A jq run-time error is a jq program error, not
including syntax errors nor JSON text input format errors.

Examples:

With stdin and multiple lines:

    $ printf '{"a":43}\n{"a":{"b":66}}\n' | ./jq '.a+1'
    44
    jq: error (at stdin:2): object and number cannot be added

With multiple files:

    $ printf '{"a":43}' > 1.json
    $ printf '{"a":"hello"}\n' > 2.json
    $ printf '{"a":{"b":66}}\n' > 3.json
    $ ./jq '[.a]|@tsv' 1.json 2.json 3.json
    "43"
    "hello"
    jq: error (at 3.json:1): object is not valid in a csv row

With very long lines (spanning multiple `fgets` calls):

    $ (  printf '{"a":43}\n' ;
         printf '{"a":{"b":[' ; seq 10000 | paste -d, -s | tr -d '\n' ;
         printf ']}}\n' ;
         printf '{"a":"hello"}\n' ) | ./jq '[.a] | @tsv'
    "43"
    jq: error (at stdin:2): object is not valid in a csv row
    "hello"

With raw input:

    $ seq 1000 | ./jq --raw-input 'select(.=="700") | . + 10'
    jq: error (at stdin:700): string and number cannot be added

Caveat:
The reported line will be the last line of the (valid) parsed JSON data.
Example:

    $ printf '{\n"a":\n"hello"\n\n\n}\n' | ./jq '.a+4'
    jq: error (at stdin:6): string and number cannot be added
2015-05-20 23:38:22 -05:00
Nicolas Williams e3cb1f76cd Report read errors too (and fix #772) 2015-05-11 21:36:26 -05:00
Nicolas Williams 07f94f82a2 usage() should check fprintf() result (fix #771) 2015-04-28 10:39:34 -05:00
Nicolas Williams 5e0e7a7ebd With inputs builtin, -n and -R can now coexist 2015-04-23 23:43:44 -05:00
Nicolas Williams 7d938487dd --slurp --raw-input is broken (fix #761) 2015-04-23 18:26:57 -05:00
Nicolas Williams 7d6d4066dd Tweak fix for #719 2015-03-24 15:05:06 -05:00
Assaf Gordon 4c22bda09b detect and report output writing errors
Detect output errors when the program exits.

Currently:
    $ echo '{}' | jq . > /dev/full && echo ok
    ok

with the patch:
    $ echo '{}' | jq . > /dev/full && echo ok
    Error: writing output failed: No space left on device

also apply to hardware/network/other I/O errors.

Signed-off-by: Nicolas Williams <nico@cryptonector.com>
2015-03-24 15:01:32 -05:00
Assaf Gordon 551d875be1 always propagate input errors to exit code
Improve robustness in automated system when using exit code in shell scripts,
by exiting with code 2 if there was any input error (even overriding other
possible error exit codes).
Exit code 2 is already used to indicate system errors.

Without the patch:
   $ jq . no-such-file ; echo $?
   jq: no-such-file: No such file or directory
   0

With the patch:
   $ jq . no-such-file ; echo $?
   jq: no-such-file: No such file or directory
   2

Signed-off-by: Nicolas Williams <nico@cryptonector.com>
2015-03-24 14:55:14 -05:00
Nicolas Williams 4f8567476d Better argfile fix (#705, fix #736) 2015-03-24 14:53:35 -05:00
Assaf Gordon 4104c4fa1c exit with non-zero code on runtime exceptions
With this change, runtime exceptions are propagated to non-zero exit
code of 'jq', allow better scripting and automation. The new exit code
value is 5.

This allows using the shell's and/or operations ('&&' and '||') to
detect input runtime exceptions.

Before:
runtime exceptions are printed to STDERR, but not reported as non-zero exit-code:
    $ echo '"hello"' | jq '.|tonumber' ; echo $?
    jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing 'hello')
    0

After:
    $ echo '"hello"' | ./jq '.|tonumber' ;  echo $?
    jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing 'hello')
    5

Note that there's a subtle interplay when using "-e" option.
The value of the non-zero exit code changes from 4 to 5, but it still
indicates a 'failure' or non-true value.

Before:
    $ echo '"hello"' | jq -e '.|tonumber' ;  echo $?
    jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing 'hello')
    4

After:
    $ echo '"hello"' | ./jq -e '.|tonumber' ;  echo $?
    jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing 'hello')
    5
2015-03-06 18:50:58 -05:00
Nicolas Williams b82c231900 Remove -i option (#704)
In-place editing should be implemented with builtins for file I/O.
2015-03-05 21:52:02 -06:00
Nicolas Williams 3d2ab93b11 Fix #705 (--argfile weirdness) 2015-02-18 18:38:11 -06:00
Nicolas Williams c86ef36769 Test in-place functionality; fix #704 2015-02-18 18:01:12 -06:00
Nicolas Williams a83a9e0bc2 Reduce number of msg callback typedefs 2015-02-13 15:58:02 -06:00
Nicolas Williams 0d414471bb Refactor moar: move parts of main.c into libjq
This adds utility functions for reading and parsing files that should be
easy to use by other apps, together with jq_start()/jq_next().
2015-02-13 15:58:02 -06:00
Nicolas Williams 91fb3df495 Refactor handling of inputs in main() (fix #667)
Much of this could be in libjq.  Eventually all of the work of reading
from files and looping over `jq_next()` should move into libjq, with
`main()` mostly doing all the command-line option processing.
2015-02-13 15:55:31 -06:00
Nicolas Williams 42ff8a6959 Usage message for -h should go to stdout 2015-01-30 10:27:46 -06:00
Nicolas Williams 7a295b30e0 Fix --raw-input 2015-01-20 00:22:24 -06:00
Nicolas Williams d927a2c185 Fix --run-tests arg handling 2015-01-12 10:43:06 -06:00
Nicolas Williams 426913f127 Fix memleak introduced run-tests enhancement 2015-01-01 02:12:08 -06:00
Nicolas Williams 86bc662bd2 Move some module tests into all.test 2014-12-31 20:09:53 -06:00
Nicolas Williams ae7f8d6ab9 Further module system revamp (fix #659)
To import a module now use:

    # Import module.jq file:
    import "relative/path/to/module" as foo;

    # Use the module's defs as foo::<def-name>

To import a JSON file:

    # Read file.json:
    import "relative/path/to/file" as $foo;
    #
    # Use as $foo::foo

Using `-L` now drops the builtin library path and appends the requested
path to the empty array (or the result of an earlier `-L`).

Support for the `$JQ_LIBRARY_PATH` environment variable has been
removed.
2014-12-31 20:09:53 -06:00
Nicolas Williams 7dc34b92af Add label $name | EXP; fix break
This is to fix the problem where `break` is dynamic, not lexical.

With this it should be possible to do this sort of thing:

    label $break | inputs | if ... then $break|error else . end

This is a backwards-incompatible change for master, but the previous
`break` hadn't shipped yet.

Still needed:

 - testing
2014-12-30 11:42:45 -06:00
Nicolas Williams 5df20f4954 Add debug builtin
And refactor setup of jv dump flags.
2014-12-27 18:25:34 -06:00
Nicolas Williams 5bfb9781f7 Add Streaming parser (--stream)
Streaming means that outputs are produced as soon as possible.  With the
`foreach` syntax one can write programs which reduce portions of the
streaming parse of a large input (reduce into proper JSON values, for
example), and discard the rest, processing incrementally.

This:

    $ jq -c --stream .

should produce the same output as this:

    $ jq -c '. as $dot | path(..) as $p | $dot | getpath($p) | [$p,.]'

The output of `jq --stream .` should be a sequence of`[[<path>],<leaf>]`
and `[[<path>]]` values.  The latter indicate that the array/object at
that path ended.

Scalars and empty arrays and objects are leaf values for this purpose.

For example, a truncated input produces a path as soon as possible, then
later the error:

    $ printf '[0,\n'|./jq -c --stream .
    [[0],0]
    parse error: Unfinished JSON term at EOF at line 3, column 0
    $
2014-12-26 23:05:56 -06:00
Nicolas Williams 9e1fd8cf4d Fix infinite loop in read_more() (fix #656) 2014-12-24 16:49:55 -06:00
Nicolas Williams a55085b662 Fix EOF handling; fix #656 2014-12-24 16:07:36 -06:00
Nicolas Williams 56ae88d9d5 Module search revamp for pkg managers
The search path listed in an import directive can now be an array.  The
top-level search path is appended.  Null and empty strings in the path
terminate any search.  The "." in "." and "./*" is replaced with the
directory containing the file doing the import (for command-line
programs this is the current directory, though that may be a bad idea).

No version numbers or anything of the sort are gratuitously added to the
search paths.

All this makes external package managers possible by allowing
dependencies to be installed local to dependents.
2014-12-24 02:31:51 -06:00
Nicolas Williams ae312bd7fe Use __attribute__ __printf__ with GCC 2014-12-23 23:22:57 -06:00
Nicolas Williams 02cf1831e9 Fix #649 2014-12-23 18:16:21 -06:00
Nicolas Williams 44c2382402 Add --argjson, fix #648 2014-12-12 16:40:07 -06:00
Nicolas Williams 89791a000b Add support for JSON sequence MIME type
Per draft-ietf-json-text-sequence-07 (which soon will be published as an
RFC).
2014-10-12 08:44:40 -05:00
Nicolas Williams 7a8e3c759e Never close stdin; allow multiple - arguments 2014-08-30 00:40:03 -05:00
Nicolas Williams b70bea8d34 Handle invalid inputs in argument files (fix #562) 2014-08-30 00:40:03 -05:00