diff --git a/Makefile b/Makefile index fc5b753..275bf01 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,10 @@ bin/csvcols: datatools.go cmds/csvcols/csvcols.go bin/csvjoin: datatools.go cmds/csvjoin/csvjoin.go go build -o bin/csvjoin cmds/csvjoin/csvjoin.go -bin/jsoncols: datatools.go dotpath/dotpath.go cmds/jsoncols/jsoncols.go +bin/jsoncols: datatools.go cmds/jsoncols/jsoncols.go go build -o bin/jsoncols cmds/jsoncols/jsoncols.go -bin/jsonrange: datatools.go dotpath/dotpath.go cmds/jsonrange/jsonrange.go +bin/jsonrange: datatools.go cmds/jsonrange/jsonrange.go go build -o bin/jsonrange cmds/jsonrange/jsonrange.go bin/xlsx2json: datatools.go cmds/xlsx2json/xlsx2json.go @@ -41,7 +41,6 @@ bin/csvfind: datatools.go cmds/csvfind/csvfind.go test: - cd dotpath && go test go test website: diff --git a/cmds/jsonrange/jsonrange.go b/cmds/jsonrange/jsonrange.go index a483184..d6df13d 100644 --- a/cmds/jsonrange/jsonrange.go +++ b/cmds/jsonrange/jsonrange.go @@ -243,7 +243,7 @@ func init() { flag.StringVar(&delimiter, "d", "", "set delimiter for range output") flag.StringVar(&delimiter, "delimiter", "", "set delimiter for range output") flag.IntVar(&limit, "limit", 0, "limit the number of items output") - flag.BoolVar(&permissive, "permissive", false, "Suppress errors messages") + flag.BoolVar(&permissive, "permissive", false, "suppress errors messages") } func main() { diff --git a/docs/jsoncols.md b/docs/jsoncols.md index 741a1d8..9cb7b91 100644 --- a/docs/jsoncols.md +++ b/docs/jsoncols.md @@ -1,17 +1,16 @@ # jsoncols -## USAGE +## USAGE: jsoncols [OPTIONS] [EXPRESSION] [INPUT_FILENAME] [OUTPUT_FILENAME] ## SYSNOPSIS -jsoncols provides for both interactive exploration of JSON structures like jid -and command line scripting flexibility for data extraction into delimited -columns. This is helpful in flattening content extracted from JSON blobs. -The default delimiter for each value extracted is a comma. This can be -overridden with an option. +jsoncols provides scripting flexibility for data extraction from JSON data +returning the results in columns. This is helpful in flattening content +extracted from JSON blobs. The default delimiter for each value +extracted is a comma. This can be overridden with an option. + EXPRESSION can be an empty stirng or dot notation for an object's path + INPUT_FILENAME is the filename to read or a dash "-" if you want to @@ -24,17 +23,21 @@ overridden with an option. ## OPTIONS ``` - -d set the delimiter for multi-field output - -h display help - -i read JSON from a file - -input read JSON from a file - -l display license - -m display output in monochrome - -r run interactively - -repl run interactively - -v display version + -d set the delimiter for multi-field output + -h display help + -i input filename + -input input filename + -l display license + -m display output in monochrome + -o output filename + -output output filename + -permissive suppress error messages + -r run interactively + -repl run interactively + -v display version ``` + ## EXAMPLES If myblob.json contained @@ -45,8 +48,8 @@ If myblob.json contained Getting just the name could be done with -``` - jsoncols .name myblob.json +```shell + jsoncols -i myblob.json .name ``` This would yeild @@ -59,8 +62,8 @@ Flipping .name and .age into pipe delimited columns is as easy as listing each field in the expression inside a space delimited string. -``` - jsoncols -d\| ".name .age" myblob.json +```shell + jsoncols -i myblob.json -d\| .name .age ``` This would yeild @@ -69,3 +72,17 @@ This would yeild "Doe, Jane"|42 ``` +You can also pipe JSON data in. + +```shell + cat myblob.json | jsoncols .name .email .age +``` + +Would yield + +``` + "Doe, Jane",jane.doe@xample.org,42 +``` + + +jsoncols v0.0.9 diff --git a/docs/jsonrange.md b/docs/jsonrange.md index 9db9c27..2b4b036 100644 --- a/docs/jsonrange.md +++ b/docs/jsonrange.md @@ -23,33 +23,36 @@ select the parts of the JSON data structure you want from the range. DOT_PATH_EXPRESSION is a dot path stale expression indicating what you want range over. E.g. -+ _._ would indicate the whole JSON data structure read is used to range over -+ _.name_ would indicate to range over the value pointed at by the "name" attribute -+ _["name"]_ would indicate to range over the value pointed at by the "name" attribute -+ _[0]_ would indicate to range over the value held in the zero-th element of the array ++ . would indicate the whole JSON data structure read is used to range over ++ .name would indicate to range over the value pointed at by the "name" attribute ++ ["name"] would indicate to range over the value pointed at by the "name" attribute ++ [0] would indicate to range over the value held in the zero-th element of the array The path can be chained together -+ _.name.family_ would point to the value heald by the "name" attributes' "family" attribute. ++ .name.family would point to the value heald by the "name" attributes' "family" attribute. + ## OPTIONS ``` - -d set delimiter for range output + -d set delimiter for range output -delimiter set delimiter for range output - -h display help - -i read JSON from file - -input read JSON from file - -l display license - -last return the index of the last element in list (e.g. length - 1) - -length return the number of keys or values - -limit limit the number of items output - -o write to output file - -output write to output file - -v display version - -values return the values instead of the keys + -h display help + -i read JSON from file + -input read JSON from file + -l display license + -last return the index of the last element in list (e.g. length - 1) + -length return the number of keys or values + -limit limit the number of items output + -o write to output file + -output write to output file + -permissive suppress errors messages + -v display version + -values return the values instead of the keys ``` + ## EXAMPLES Working with a map @@ -82,6 +85,7 @@ This would yield 42 ``` + Working with an array ```shell @@ -147,3 +151,4 @@ would yield 2 ``` +jsonrange v0.0.9