Crates.io | json2file |
lib.rs | json2file |
version | 1.7.8 |
source | src |
created_at | 2022-12-20 19:57:13.693477 |
updated_at | 2024-03-20 17:24:49.749497 |
description | Generate file output from JSON |
homepage | https://github.com/tj-actions/json2file |
repository | https://github.com/tj-actions/json2file |
max_upload_size | |
id | 742566 |
size | 181,095 |
Simplifies the process of serializing JSON data to a file.
...
- name: Set output
id: set-output
run: |
echo "color=green" >> $GITHUB_OUTPUT
- name: Generate file output from json
uses: tj-actions/json2file@v1
with:
directory: 'output'
outputs: ${{ toJSON(steps.set-output.outputs) }}
keys: 'color'
extension: 'txt'
...
The above example will create a file named color.txt
in the output
directory with the contents green
.
$ cat ./output/color.txt
green
INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
---|---|---|---|---|
bin_path | string | false | Path to the binary | |
directory | string | true | ".github/outputs" |
Directory to write to |
extension | string | false | "txt" |
File extension to use, possible values: txt, json |
keys | string | true | List of Keys to read from the outputs JSON string |
|
outputs | string | true | JSON string | |
skip_missing_keys | string | false | "false" |
Skip missing keys not found in the outputs JSON string |
To install json2file
, open a terminal window (Command Prompt or PowerShell on Windows) and run the following command:
cargo install json2file
If you prefer to build from the source, follow these steps:
git clone https://github.com/tj-actions/json2file
cd json2file
cargo build --release
Run json2file --help
for more information.
$ json2file --help
Generate file output from JSON
Usage: json2file [OPTIONS] --keys <KEYS> --outputs <OUTPUTS> --directory <DIRECTORY>
Options:
-k, --keys <KEYS> Space delimited list of keys to extract from the JSON output
-o, --outputs <OUTPUTS> The JSON output to use
-d, --directory <DIRECTORY> The directory to output the files to
-s, --skip-missing-keys Skip missing keys
-e, --extension <EXTENSION> The extension to use for the files [default: txt] [possible values: txt, json, csv]
-v, --verbose
-h, --help Print help
-V, --version Print version
Run
json2file --keys="foo bar" --outputs="{\"foo\": \"value1\", \"bar\": \"value2\"}" --directory=/tmp --extension=txt
This creates two files with the following contents:
foo.txt
value1
bar.txt
value2
If you feel generous and want to show some extra appreciation:
This package was created with Cookiecutter using cookiecutter-action
Report bugs at https://github.com/tj-actions/json2file/issues.
If you are reporting a bug, please include: