Skip to content

JSON Tools

🛠️ Tools · ⬅ Top


Depends on jq which is also recommended for Zesk Build.

jsonField

Fetch a non-blank field from a JSON file with error

Usage

jsonField [ --help ] handler jsonFile [ ... ]

Fetch a non-blank field from a JSON file with error handling Return Code: 0 - Field was found and was non-blank Return Code: 1 - Field was not found or is blank

Writes to standard output

selected field

Writes to standard error

error messages

Arguments

  • --help - Optional. Flag. 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 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

jq whichExists throwEnvironment printf rm decorate head

jsonPath

Generate jq paths

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 - Success
  • 1 - Environment error
  • 2 - Argument error

jsonSetValue

Sets the value of a variable in a JSON file

Usage

jsonSetValue [ --filter ] [ --status ] [ --quiet ] [ --generator ] [ --value ] [ --key ] key file

Sets the value of a variable in a JSON file

Return Code: 0 - File was updated successfully. Return Code: 1 - Environment error Return Code: 2 - Argument error Return Code: 105 - Identical files (only when --status is passed)

Arguments

  • --filter - Function. Optional. Run value through this filter prior to inserting into the JSON file.
  • --status - Flag. Optional. When set, returns 0 when the value was updated successfully and $(returnCode identical) when the values is the same
  • --quiet - Flag. Optional. Do not output anything to stdout and just do the action and exit.
  • --generator - Function. Optional. Function to generate the value. Defaults to hookVersionCurrent.
  • --value - String. Optional. Value to set in JSON file. (Skips generation)
  • --key - String. Optional. Key to set in JSON file. Defaults to version.
  • key - Required. If not specified as --key, specify it here.
  • file - File. Required. Modify and update this file

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

jsonFileGet

Get a value in a JSON file

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 - Success
  • 1 - Environment error
  • 2 - Argument error

jsonFileSet

Set or delete a value in a JSON file

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 - Success
  • 1 - Environment error
  • 2 - Argument error