debian/0000755000000000000000000000000012243031364007164 5ustar debian/compat0000644000000000000000000000000212233556560010373 0ustar 9 debian/source/0000755000000000000000000000000012233556560010475 5ustar debian/source/format0000644000000000000000000000001412233556560011703 0ustar 3.0 (quilt) debian/control0000644000000000000000000000172112243026124010566 0ustar Source: jshon Section: utils Priority: optional Maintainer: Jordan Metzmeier Build-Depends: debhelper (>= 9.0.0), libjansson-dev Standards-Version: 3.9.4 Homepage: http://kmkeen.com/jshon/ Package: jshon Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Command line tool to parse, read and create JSON Jshon is a command line utility to parse, read and create JSON. It is designed to be as usable as possible from within the shell and replaces fragile adhoc parsers made from grep/sed/awk as well as heavyweight one-line parsers made from Perl/Python. Jshon loads json text from stdin, performs actions, then displays the last action on stdout. . Json parsing features include: Return data types of values Report data type lengths Sort JSON data by keys In-place editing of JSON files Format or "beautify" JSON (as changing indentation, etc) Create JSON from an empty object Extraction of keys and valuesdebian/changelog0000644000000000000000000000131712243031203011030 0ustar jshon (20131010-3) unstable; urgency=low * More improvements package description * Add JSON creation example to the manpage * Fix segfault when -F is given a file that does not exist -- Jordan Metzmeier Tue, 19 Nov 2013 21:54:43 -0600 jshon (20131010-2) unstable; urgency=low * License debian/* files to Expat to match upstream * Better descriptions for the binary package and patches * Remove boilerplate comments from debian/rules -- Jordan Metzmeier Thu, 07 Nov 2013 12:07:21 -0600 jshon (20131010-1) unstable; urgency=low * Initial release (Closes: #697530) -- Jordan Metzmeier Mon, 28 Oct 2013 15:04:23 -0500 debian/rules0000755000000000000000000000013712236753040010251 0ustar #!/usr/bin/make -f # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@ debian/copyright0000644000000000000000000000452312236751534011135 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: jshon Source: https://github.com/keenerd/jshon Files: * Copyright: 2011 Kyle Keen License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Files: debian/* Copyright: 2013 Jordan Metzmeier License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. debian/patches/0000755000000000000000000000000012243031357010615 5ustar debian/patches/remove_werror0000644000000000000000000000060112236752624013443 0ustar # From: Jordan Metzmeier # Subject: Remove -Werror from compilation since it FTBS # on newer versions of GCC --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # jshon - command line JSON parsing -CFLAGS := -std=c99 -Wall -pedantic -Wextra -Werror ${CFLAGS} +CFLAGS := -std=c99 -Wall -pedantic -Wextra ${CFLAGS} LDLIBS = -ljansson INSTALL=install DESTDIR?=/ debian/patches/manpage_fixes0000644000000000000000000001630312236752751013363 0ustar # From: Jordan Metzmeier # Subject: Fix macro errors in manpage and convert hyphens to minus signs. # Hypens can cause issues with copy and pasting examples from the manpage --- a/jshon.1 +++ b/jshon.1 @@ -7,7 +7,7 @@ .Nd JSON parser for the shell .Sh SYNOPSIS .Nm jshon --[P|S|Q|V|C|I|0] [-F path] -[t|l|k|u|p|a] -[s|n] value -[e|i|d] index +\-[P|S|Q|V|C|I|0] [\-F path] \-[t|l|k|u|p|a] \-[s|n] value \-[e|i|d] index .Sh DESCRIPTION .Nm parses, reads and creates JSON. It is designed to be as usable as possible from within the shell and replaces fragile adhoc parsers made from grep/sed/awk as well as heavyweight one-line parsers made from perl/python. @@ -38,69 +38,70 @@ .It Cm -t (type) returns string, object, array, number, bool, null .Pp -\& jshon -t -> object +\& jshon \-t -> object .Pp .It Cm -l (length) returns an integer. Only works on string, object, array. .Pp -\& jshon -l -> 3 +\& jshon \-l -> 3 .Pp .It Cm -k (keys) returns a newline separated list of keys. Only works on object. .Pp -\& jshon -k -> a b c +\& jshon \-k -> a b c .Pp .It Cm -e index (extract) returns json value at "index". Only works on object, array. The index of an array is an integer. .Pp -\& jshon -e c -> {"d":4,"e":5} +\& jshon \-e c -> {"d":4,"e":5} .Pp .It Cm -a (across) maps the remaining actions across the selected element. Only works on objects and arrays. Multiple .Nm \-a calls can be nested, though the need is rare in practice. .Pp -\& jshon -e b -a -t -> bool bool null string +\& jshon \-e b \-a \-t -> bool bool null string .Pp .It Cm -s value -(string) returns a json encoded string. Can later be (-i)nserted to an existing structure. +(string) returns a json encoded string. Can later be (\-i)nserted to an existing structure. .Pp -\& jshon -s "back\[rs]slash" -> "back\[rs]\[rs]slash" +\& jshon \-s "back\[rs]slash" -> "back\[rs]\[rs]slash" .Pp .It Cm -n value -(nonstring/number) returns a json element. Can later be (-i)nserted to an existing structure. Valid values are 'true', 'false', 'null', 'array', 'object', integers and floats. Abbreviations t, f, n, [] and {} respectively also work. +(nonstring/number) returns a json element. Can later be (\-i)nserted to an existing structure. Valid values are 'true', 'false', 'null', 'array', 'object', integers and floats. Abbreviations t, f, n, [] and {} respectively also work. .Pp -\& jshon -n object -> {} +\& jshon \-n object -> {} .Pp .It Cm -u (unstring) returns a decoded string. Only works on simple types: string, int, real, boolean, null. .Pp -\& jshon -e b -e 3 -u -> str +\& jshon \-e b \-e 3 \-u -> str .Pp .It Cm -p (pop) pops the last manipulation from the stack, rewinding the history. Useful for extracting multiple values from one object. .Pp -\& jshon -e c -e d -u -p -e e -u -> 4 5 +\& jshon \-e c \-e d \-u \-p \-e e \-u -> 4 5 .Pp .It Cm -d index (delete) removes an item in an array or object. Negative array indexes will wrap around. .Pp -\& jshon -d b -> {"a":1,"c":{"d":4,"e":5}} +\& jshon \-d b -> {"a":1,"c":{"d":4,"e":5}} .Pp .It Cm -i index (insert) is complicated. It is the reverse of extract. Extract puts a json sub-element on the stack. Insert removes a sub-element from the stack, and inserts that bit of json into the larger array/object underneath. Use extract to dive into the json tree, delete/string/nonstring to change things, and insert to push the changes back into the tree. .Pp -\& jshon -e a -i a -> the orginal json +\& jshon \-e a \-i a -> the orginal json .br -\& jshon -s one -i a -> {"a":"one", ...} +\& jshon \-s one \-i a -> {"a":"one", ...} .Pp Arrays are handled in a special manner. Passing integers will insert a value without overwriting. Negative integers are acceptable, as is the string 'append'. To overwrite a value in an array: delete the index, .Nm \-n/s the new value, and then insert at the index. .Pp -\& jshon -e b -d 0 -s q -i 0 -> {"b":"q",false,null,"str"} +\& jshon \-e b \-d 0 \-s q \-i 0 -> {"b":"q",false,null,"str"} . .Pp +.El .Sh NON-MANIPULATION There are several meta-options that do not directly edit json. Call these at most once per invocation. .Pp @@ -122,11 +123,11 @@ .Nm running several times slower while using several times more memory. However by-value is safer than by-reference and generally causes less surprise. By-reference is enabled by default because there is no risk during read-only operations and generally makes editing json more convenient. .Pp -\& jshon -e c -n 7 -i d -p -> c["d"] == 7 +\& jshon \-e c \-n 7 \-i d \-p -> c["d"] == 7 .br -\& jshon -V -e c -n 7 -i d -p -> c["d"] == 5 +\& jshon \-V \-e c \-n 7 \-i d \-p -> c["d"] == 5 .br -\& jshon -V -e c -n 7 -i d -i c -> c["d"] == 7 +\& jshon \-V \-e c \-n 7 \-i d \-i c -> c["d"] == 7 .Pp With .Nm \-V @@ -136,20 +137,21 @@ (continue) on potentially recoverable errors. For example, extracting values that don't exist will add 'null' to the edit stack instead of aborting. Behavior may change in the future. .Pp .It Cm -I -(in-place) file editing. Requires a file to modify and so only works with -F. This is meant for making slight changes to a json file. When used, normal output is suppressed and the bottom of the edit stack is written out. +(in-place) file editing. Requires a file to modify and so only works with \-F. This is meant for making slight changes to a json file. When used, normal output is suppressed and the bottom of the edit stack is written out. .Pp .It Cm -0 -(null delimiters) Changes the delimiter of -u from a newline to a null. This option only affects -u because that is the only time a newline may legitimately appear in the output. +(null delimiters) Changes the delimiter of \-u from a newline to a null. This option only affects \-u because that is the only time a newline may legitimately appear in the output. .Pp .It Cm --version Returns a YYYYMMDD timestamp and exits. . .Pp +.El .Sh OTHER TOOLS .Nm always outputs one field per line. Many unix tools expect multiple tab separated fields per line. Pipe the output through 'paste' to fix this. However, paste can not handle empty lines so pad those with a placeholder. Here is an example: .Pp -\& jshon ... | sed 's/^$/-/' | paste -s -d '\\t\\t\\n' +\& jshon ... | sed 's/^$/\-/' | paste \-s \-d '\\t\\t\\n' .Pp This replaces blanks with '-' and merges every three lines into one. .Pp @@ -157,9 +159,9 @@ .Nm once for each line) or convert it to a legitimate json array. For example: .Pp -\& while read line; do jshon <<< "$line"; done < <(journalctl -o json) +\& while read line; do jshon <<< "$line"; done < <(journalctl \-o json) .Pp -\& journalctl -o json | sed -e '1i[' -e '$!s/$/,/' -e '$a]' | jshon +\& journalctl \-o json | sed \-e '1i[' \-e '$!s/$/,/' \-e '$a]' | jshon .Pp . .Pp @@ -168,7 +170,7 @@ .Nm \-p(op) can be golfed as follows: .Pp -\& jshon -e c -e d -u -p -e e -u == jshon -ec -ed -upee -u +\& jshon \-e c \-e d \-u \-p \-e e \-u == jshon \-ec \-ed \-upee \-u .Pp I do not recommend doing this (it makes things much harder to understand) but some people golf despite the consequences. . @@ -190,4 +192,3 @@ .Pp .Sh BUGS Numerous! Floats may lose precision. Could be more convenient to use. Documentation is brief. - debian/patches/series0000644000000000000000000000011612243030020012012 0ustar remove_werror manpage_fixes manpage_add_example fix_segfault_nonexistent_file debian/patches/fix_segfault_nonexistent_file0000644000000000000000000000164712243031034016655 0ustar # From: Jordan Metzmeier # Subject: Fix segfault when -F is a file that does not exist # When -F is passed a file that does not exist, jshon was attempting to # read from a null pointer. This patch checks the pointer to make sure it # is not null. If it is, it will print an error to stderr and exit --- a/jshon.c +++ b/jshon.c @@ -373,6 +373,10 @@ FILE* fp; char* content; fp = fopen(path, "r"); + if ( !fp ) { + fprintf(stderr, "unable to read file %s: %s\n", path, strerror(errno)); + return NULL; + } content = read_stream(fp); fclose(fp); return content; @@ -918,6 +922,11 @@ {content = read_file(file_path);} else {content = read_stdin();} + if (!content) { + fprintf(stderr, "error: failed to read input\n"); + exit(1); + } + if (!content[0] && !quiet) {fprintf(stderr, "warning: nothing to read\n");} debian/patches/manpage_add_example0000644000000000000000000000111612243031357014472 0ustar # From: Jordan Metzmeier # Subject: Add an example of how jshon can be used to create JSON # The description of jshon includes it's ability to create JSON. Examples # of how to do this were not present in any of the documentation --- a/jshon.1 +++ b/jshon.1 @@ -175,6 +175,13 @@ I do not recommend doing this (it makes things much harder to understand) but some people golf despite the consequences. . .Pp +.Sh CREATING JSON +.Nm +can create json by passing an empty object as input: +.Pp +\& jshon \-s one \-i a <<< "{}" +. +.Pp .Sh AUTHORS .An -nosplit .Pp debian/watch0000644000000000000000000000016412233556560010227 0ustar # The upstream site doesn't have a reliable way of implement uscan. The # tarballs available there are not versioneddebian/TODO0000644000000000000000000000033412243024516007655 0ustar * Get upstream to provid a download method that can be used by uscan * Submit build system patches upstream * Create patch for compiler warning and submit upstream * Make unit tests * Fix segfaults when -F doesn't exist