Json

Simple json manipulation. These functions does not completely replace jq in any way.

Table of Contents


json::get_value()

Extract value from json based on key and position. Input to the function can be a pipe output, here-string or file.

Arguments

  • $1 (string): id of the field to fetch.
  • $2 (int): position of value to extract.Defaults to 1.(optional)

Exit codes

  • 0: If match successful.
  • 2: Function missing arguments.

Output on stdout

  • string value of extracted key.

Example

json::get_value "id" "1" < json_file
json::get_value "id" <<< "${json_var}"
echo "{\"data\":{\"id\":\"123\",\"value\":\"name string\"}}" | json::get_value "id"