JSON Tools
Depends on jq which is also recommended for Zesk Build.
Usage
json [ --help ]
Format something neatly as JSON
Reads standard input
JSONFile
Writes to standard output
JSONFile pretty formatted
Arguments
--help- Flag. Optional. Display this help.
Examples
json < inputFile > outputFile
Return codes
0- Success1- Environment error2- Argument error
Usage
jsonField [ --help ] handler jsonFile [ ... ]
Fetch a non-blank field from a JSON file with error handling
Writes to standard output
selected field
Writes to standard error
error messages
Arguments
--help- Flag. Optional. Display this help.handler- Function. Required. Error handler.jsonFile- File. Required. A JSON file to parse...- Arguments. Optional. Passed directly to jq
Return codes
0- Field was found and was non-blank1- Field was not found or is blank
Requires
jq executableExists throwEnvironment printf rm decorate head
Usage
jsonPath [ path ]
Generate a path for a JSON structure for use in jq queries
Without arguments, displays help.
Arguments
path- String. Output a json path separated by dots.
Return codes
0- Success1- Environment error2- Argument error
Usage
jsonSetValue [ --filter ] [ --status ] [ --quiet ] [ --generator ] [ --value ] [ --key ] key file
Sets the value of a variable in a JSON file
Arguments
--filter- Function. Optional. Run value through this filter prior to inserting into the JSON file.--status- Flag. Optional. When set, returns0when the value was updated successfully and$(returnCode identical)when the values is the same--quiet- Flag. Optional. Do not output anything tostdoutand just do the action and exit.--generator- Function. Optional. Function to generate the value. Defaults tohookVersionCurrent.--value- String. Optional. Value to set in JSON file. (Skips generation)--key- String. Optional. Key to set in JSON file. Defaults toversion.key- Required. If not specified as--key, specify it here.file- File. Required. Modify and update this file
Return codes
0- File was updated successfully.1- Environment error2- Argument error105- Identical files (only when --status is passed)
Usage
jsonFileGet jsonFile path
Get a value in a JSON file
Arguments
jsonFile- File. Required. File to get value from.path- String. Required. dot-separated path to get
Return codes
0- Success1- Environment error2- Argument error
Usage
jsonFileSet jsonFile path [ value ... ]
Set or delete a value in a JSON file
Arguments
jsonFile- File. Required. File to get value from.path- String. Required. dot-separated path to modify (e.g.extra.fingerprint)value ...- EmptyString. Optional. Value to set. If more than one value is set, value is set to an array value. If no value passed, the key is deleted. Note the difference between a blank argument and NO argument.
Return codes
0- Success1- Environment error2- Argument error