Skip to content

Commit

Permalink
feat(components): Added JSON query components (#4601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Oct 12, 2020
1 parent 329ed48 commit b656fbf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
24 changes: 24 additions & 0 deletions components/json/Get_element_by_index/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Get element by index from JSON
inputs:
- {name: Json}
- {name: Index, type: Integer}
outputs:
- {name: Output}
metadata:
annotations:
author: Alexey Volkov <alexey.volkov@ark-kun.com>
implementation:
container:
image: stedolan/jq:latest
command:
- sh
- -exc
- |
input_path=$0
output_path=$1
index=$2
mkdir -p "$(dirname "$output_path")"
< "$input_path" jq --raw-output .["$index"] > "$output_path"
- {inputPath: Json}
- {outputPath: Output}
- {inputValue: Index}
24 changes: 24 additions & 0 deletions components/json/Get_element_by_key/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Get element by key from JSON
inputs:
- {name: Json}
- {name: Key, type: String}
outputs:
- {name: Output}
metadata:
annotations:
author: Alexey Volkov <alexey.volkov@ark-kun.com>
implementation:
container:
image: stedolan/jq:latest
command:
- sh
- -exc
- |
input_path=$0
output_path=$1
key=$2
mkdir -p "$(dirname "$output_path")"
< "$input_path" jq --raw-output '.["'"$key"'"]' > "$output_path"
- {inputPath: Json}
- {outputPath: Output}
- {inputValue: Key}
27 changes: 27 additions & 0 deletions components/json/Query/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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>
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}

0 comments on commit b656fbf

Please sign in to comment.