JSON Utils
Version updated for yakubique/json-utils to version v1.6.
- This action is used across all versions by 1 repositories.
Go to the GitHub Marketplace to find the latest changes.
Release notes
json-utils
Full Changelog: https://github.com/yakubique/json-utils/compare/v1.5...v1.6 A collection of handy utilities for working with JSON in GitHub Actions, making it easier to manipulate JSON data
For live examples, please see actions
Methods:
Diff
Flat
Order and values are taken from input
. In this case it’s ["1.3.0"]
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
secondary: '["1.0.0","1.1.0","1.2.0","1.2.1"]'
action: "diff"
# result: "["1.3.0"]"
It’ll return nothing if change direction
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1"]'
secondary: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
action: "diff"
# result: "[]"
With nested json
Find diff using name
field in object
uses: yakubique/json-utils@v1.6
with:
input: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"},{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]'
secondary: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"}]'
action: "diff"
type: "nested-json"
key: "name"
# result: "[{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]"
Use output
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Diff two arrays
id: diff_two_arrays
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
secondary: '["1.0.0","1.1.0","1.2.0","1.2.1"]'
action: "diff"
- name: Test 1
run: |
echo "Expecting ['1.3.0']"
echo "${{ steps.diff_two_arrays.outputs.result }}"
test "${{ steps.diff_two_arrays.outputs.result }}" == "[1.3.0]"
Sort
Flat
By default it’s Ascending
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
action: "sort"
Descending
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
action: "sort"
modifier: "desc"
With nested json
Find diff using name
field in object
uses: yakubique/json-utils@v1.6
with:
input: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"},{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]'
action: "sort"
type: "nested-json"
key: "name"
modifier: "desc"
Use output
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Sort array of strings
id: sort_array
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
action: "sort"
modifier: "desc"
- name: Test 1
run: |
echo "Expecting [1.3.0,1.2.1,1.2.0,1.1.0,1.0.0]"
echo "${{ steps.sort_array.outputs.result }}"
Pick
Creates an object composed of the picked object properties.
- name: Pick "name"
uses: yakubique/json-utils@v1.6
with:
input: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"},{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]'
action: "pick"
key: "name"
Works with multiple comma-separated keys
- name: Pick "name"
uses: yakubique/json-utils@v1.6
with:
input: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"},{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]'
action: "pick"
key: "name,prerelease"
# returns: [{name:v0.3.26,prerelease:false},{name:v0.3.22,prerelease:false},{name:v0.3.23,prerelease:false},{name:v0.3.25,prerelease:false},{name:v0.3.31,prerelease:false},{name:v0.3.34,prerelease:false}]
Get
Return only value of picket object property.
- name: Get "name"
id: get_name
uses: yakubique/json-utils@v1.6
with:
input: '[{"name":"v0.3.26","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"v0.3.22","tag_name":"v0.3.22","prerelease":false,"published_at":"2023-11-12T10:58:00Z"},{"name":"v0.3.23","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"v0.3.25","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"v0.3.31","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"},{"name":"v0.3.34","tag_name":"v0.3.34","prerelease":false,"published_at":"2023-11-12T11:21:59Z"}]'
action: "get"
key: "name"
# returns: [v0.3.26,v0.3.22,v0.3.23,v0.3.25,v0.3.31,v0.3.34]
Concat
Concat input
and secondary
JSON arrays
- name: Concat two arrays
uses: yakubique/json-utils@v1.6
with:
input: '["1.0.0","1.1.0",]'
secondary: '["1.2.0","1.2.1","1.3.0"]'
action: "concat"
# returns: ["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]
Chunk
Creates an array of elements split into groups the length of modifier
. If array can’t be split evenly, the final chunk
will be the remaining elements.
- name: Chunk array
uses: yakubique/json-utils@v1.6
with:
input: '[1,2,3,4,5]'
action: "chunk"
modifier: 3
# returns: [[1,2,3],[4,5]]
Inputs
INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
---|---|---|---|---|
action | string | true | What to do with input JSON (available: “diff”, “get”, “pick”, “sort”, “concat”, “chunk”) | |
input | string | true | JSON string/Value from other action | |
secondary | string | false | Secondary JSON string/Value from other action (useful for some actions) | |
key | string | false | If type="nested-json" - which key should be used | |
modifier | string | false | Suitable modifier for performed action (ex: ‘ASC’/‘DESC’ for ‘sort’) | |
type | string | false | "flat-json" | Type of input data ["flat-json", "nested-json"] (default: “flat-json”) |
from_file | string | false | "false" | Load input from file (applied to secondary too) |
to_file | string | false | "false" | Output to file |
Outputs
OUTPUT | TYPE | DESCRIPTION |
---|---|---|
result | string | Processed JSON |