https://github.com/yakubique/filter-json
Github Action to filter value inside JSON
https://github.com/yakubique/filter-json
github-actions json processing
Last synced: about 2 months ago
JSON representation
Github Action to filter value inside JSON
- Host: GitHub
- URL: https://github.com/yakubique/filter-json
- Owner: yakubique
- License: mit
- Created: 2024-01-28T07:41:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-22T08:27:11.000Z (about 2 years ago)
- Last Synced: 2025-06-05T20:05:57.339Z (about 1 year ago)
- Topics: github-actions, json, processing
- Language: TypeScript
- Homepage:
- Size: 208 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# filter-json
[](./badges/coverage.svg)
GitHub Action filters JSON values based on predefined criteria, extracting and retaining desired values.
## Usage
For live examples, please see [actions](https://github.com/yakubique/filter-json/actions/workflows/test-myself.yaml)
```yaml
uses: yakubique/filter-json@v1.2
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
values: "1.0.0"
# result: '["1.1.0","1.2.0","1.2.1","1.3.0"]'
```
## With multiple values
```yaml
uses: yakubique/filter-json@v1.2
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
values: '1.0.0,1.1.0'
# result: "["1.2.0","1.2.1","1.3.0"]"
```
## With nested json
```yaml
uses: yakubique/filter-json@v1.2
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"}]'
type: "nested-json"
key: "name"
values: 'v0.3.22,v0.3.34'
# result: "[{"name":"The name is:v0.3.26.","tag_name":"v0.3.26","prerelease":false,"published_at":"2023-08-07T09:43:28Z"},{"name":"The name is:v0.3.23.","tag_name":"v0.3.23","prerelease":false,"published_at":"2023-11-12T10:59:27Z"},{"name":"The name is:v0.3.25.","tag_name":"v0.3.25","prerelease":false,"published_at":"2023-11-12T11:01:20Z"},{"name":"The name is:v0.3.31.","tag_name":"v0.3.31","prerelease":false,"published_at":"2023-11-12T11:17:17Z"}]"
```
## Use output
```yaml
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Filter JSON
id: filter_single_value
uses: yakubique/filter-json@v1.2
with:
input: '["1.0.0","1.1.0","1.2.0","1.2.1","1.3.0"]'
values: "1.0.0"
- name: Echo output
run: |
echo "${{ steps.filter_single_value.outputs.result }}"
```
## Inputs
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------|--------|----------|---------------|--------------------------------------------------------------------------|
| input | string | true | | JSON to filter |
| type | string | false | `"flat-json"` | Type of input data `["flat-json", "nested-json"]` (default: "flat-json") |
| key | string | false | | If `type="nested-json"` - which key should
be used |
| values | string | true | | Values to filter from JSON, comma
separated |
| from_file | string | false | `"false"` | Get JSON from file |
| to_file | string | false | | Output to JSON file |
## Outputs
| OUTPUT | TYPE | DESCRIPTION |
|--------|--------|--------------------------------------------------------------------|
| result | string | Input JSON minus `values` (JSON or filepath, depends on `to_file`) |
----
[](https://ko-fi.com/S6S1UZ9P7)