name: Query JSON using JQ
inputs:
- {name: Json}
- {name: Query, type: String}
- {name: Options, type: String, default: '--raw-output'}
outputs:
- {name: Output}
metadata:
  annotations:
    author: Alexey Volkov <alexey.volkov@ark-kun.com>
    canonical_location: 'https://raw.githubusercontent.com/Ark-kun/pipeline_components/master/components/json/Query/component.yaml'
implementation:
  container:
    image: stedolan/jq:latest
    command:
    - sh
    - -exc
    - |
      input_path=$0
      output_path=$1
      query=$2
      options=$3
      mkdir -p "$(dirname "$output_path")"
      < "$input_path" jq $options "$query" > "$output_path"
    - {inputPath: Json}
    - {outputPath: Output}
    - {inputValue: Query}
    - {inputValue: Options}
