An open API service indexing awesome lists of open source software.

https://github.com/benlei/json2outputs

This action will read in a JSON body / file and set them as outputs
https://github.com/benlei/json2outputs

github-actions json workflows

Last synced: about 1 month ago
JSON representation

This action will read in a JSON body / file and set them as outputs

Awesome Lists containing this project

README

          

# benlei/json2outputs

![CI](https://github.com/benlei/json2outputs/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/benlei/json2outputs/actions/workflows/check-dist.yml/badge.svg)](https://github.com/benlei/json2outputs/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/benlei/json2outputs/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/benlei/json2outputs/actions/workflows/codeql-analysis.yml)
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)

Reads in a `json` input (or `file` input) and tries to output its values in dot
notation. Note that if the json/file is a primitive/missing/has errors, nothing
will be output.

For example given the JSON:

```json
{
"foo": {
"bar": [1, 2, 3]
},
"hello": {
"world": "abc",
"example.com/foobar": "bye",
"yes": true,
"no": false
}
}
```

Should output the following:

- `steps.my-id.outputs['foo.bar[0]'] = '1'`
- `steps.my-id.outputs['foo.bar[1]'] = '2'`
- `steps.my-id.outputs['foo.bar[2]'] = '3'`
- `steps.my-id.outputs['hello.world'] = 'abc'`
- `steps.my-id.outputs['hello["example.com/foobar"]'] = 'bye'`
- `steps.my-id.outputs['hello.yes'] = 'true'`
- `steps.my-id.outputs['hello.no'] = 'false'`

## Inputs

| Input Name | Required | Default | Description |
| ---------- | -------- | ------- | ---------------------------------------------------------------- |
| `json` | no | `''` | The JSON body (string) to parse |
| `file` | no | `''` | The JSON file to parse. Ignored if `json` has a non-empty value. |

## Outputs

Varies depending on inputs.

## Examples

### Passing in a raw JSON body

```yaml
- name: Test
id: json
uses: benlei/json2outputs@v1
with:
json: |
{
"foo": {
"bar": [1, 2, 3]
},
"hello": {
"world": "abc",
"example.com/foobar": "bye",
"yes": true,
"no": false
}
}

- name: Output value:
run: |
echo ${{ steps.json.outputs['hello["example.com/foobar"]'] }}
```

### Passing in a JSON file

```yaml
- name: Test
id: json
uses: benlei/json2outputs@v1
with:
file: ./some.json

- name: Output value:
run: |
echo ${{ steps.json.outputs['hello["example.com/foobar"]'] }}
```