#!/bin/sh
#
# jsonpaths - outputs JSON paths
#
# usage:
#     curl -s https://raw.githubusercontent.com/sitepoint-editors/json-examples/master/src/db.json | ./jsonpaths
#
# ---
# source: https://gist.github.com/fernandoacorreia/4b67a41bbe227654868df5eb3ca311d7

jq -r --stream '
  select(length > 1)
  | (
    .[0] | map(
      if type == "number"
      then "[" + tostring + "]"
      else "." + .
      end
    ) | add
  ) + " = " + (.[1] | @json)
'
