json2yaml 6.0.0
dotnet tool install --global json2yaml --version 6.0.0
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local json2yaml --version 6.0.0
#tool dotnet:?package=json2yaml&version=6.0.0
nuke :add-package json2yaml --version 6.0.0
json2yaml
A simple tool to convert json to yaml.
json2yaml converter reads json input (from file, url endpoint or stdin) and produces converted yaml output (to file or stdout).
Installation
dotnet tool install --global json2yaml
By default .NET will choose which runtime to target.
You can use specific framework version if you want to run tool on different runtime:
dotnet tool install json2yaml --global --framework net8.0
This tool supports roll-forward Major behavior. It means it is possible to use tool not only with targeted runtimes, but with newer major ones as well.
Usage
Usage: json2yaml [options]
Options:
-i|--input Path to json input file. E.g. `-i:file.json` (or `-i="file.json"`). If empty value
provided (`-i`), converter will search current directory for *.json file.
-u|--url HTTP endpoint to fetch json input from.
--skip-content-type-check Flag specifies if http response Content-Type header check can be skipped. Only in
effect when -u option is provided.
-c|--console-output Flag specifies if converted yaml should be printed directly to console. (In this
case -o option is ignorred.)
-o|--output Path to output yaml file. E.g. `-o:file.yaml (or -o="file.yaml")`. If omitted or
empty value provided ('-o') converter will output to file named like input file or
the last segment of url, but with .yaml extension. Required if input is read from
stdin.
-m|--max-size Specifies size limit for file to be converted. E.g. `-m:10`. If omitted, converter
will skip file larger that 20 MB. Respected only when used together with -i option.
--format-null-as Yaml can represent null in different ways. Supported values:
null|Null|NULL|~|empty. Default is "null".
--json-framework framework to use for json parser. Supported values: system|newtonsoft. Default is
"system".
--version Shows tool version. If more options are provided this option is ignored.
-v|--verbose Verbose output. Shows more details on errors.
-?|-h|--help Show help information
Examples
The simplest use case to take input from file:
json2yaml -i
This will search current directory for json file. Convert its contents to yaml. And writes output to file named as input file, but with extension .yaml.
For remote input use this:
json2yaml -u:https://localhost:5001/swagger/v1/swagger.json
This will fetch json from provided endpoint and will write content to swagger.yaml
file.
To change output file name use -o|--output
option:
json2yaml -u:https://localhost:5001/swagger/v1/swagger.json -o:api.yaml
To print conversion results directly to console use -c|--console-output
flag:
json2yaml -i:input.json -c
Read input from stdin:
cat test.json | json2yaml -o:output.yaml
Format yaml output. Represent null as ~:
echo "[null, null]" | json2yaml -c --format-null-as:~
prints result:
- ~
- ~
Tool supports full piping scenarios:
cat swagger.json | json2yaml -c | grep version
Note
Since version 4.0.0
tool can use differnet json framework for json parsing (either Newtonsoft.Json or System.Text.Json)
By default System.Text.Json is used. (Default framework chaned in version 6.0.0
.)
Which framework to use can be set by --json-framework
option:
json2yaml -i:input.json --json-framework:newtonsoft
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
6.0.0 | 89 | 11/20/2024 |
5.1.0 | 95 | 11/18/2024 |
5.0.0 | 4,131 | 12/28/2022 |
4.0.0 | 371 | 12/1/2022 |
3.0.1 | 2,660 | 11/28/2021 |
2.2.0 | 414 | 10/9/2021 |
2.1.0 | 537 | 12/20/2020 |
2.0.0 | 559 | 7/9/2020 |
1.3.0 | 576 | 5/31/2020 |
1.2.7 | 533 | 4/18/2020 |
1.2.6 | 537 | 3/6/2020 |
1.2.5 | 604 | 12/23/2019 |
1.2.4 | 534 | 12/23/2019 |
1.2.3 | 557 | 12/21/2019 |
1.2.2 | 556 | 12/18/2019 |
1.2.1 | 545 | 11/9/2019 |
1.2.0 | 546 | 11/9/2019 |
1.1.0 | 591 | 10/21/2019 |
1.0.5 | 702 | 9/9/2019 |
1.0.4 | 680 | 8/10/2019 |
1.0.3 | 648 | 7/7/2019 |
1.0.2 | 591 | 6/13/2019 |
1.0.1 | 614 | 5/18/2019 |
1.0.0 | 616 | 5/15/2019 |
0.4.0 | 934 | 4/6/2019 |
0.3.2 | 811 | 1/20/2019 |
0.3.1 | 704 | 12/17/2018 |
0.3.0 | 777 | 12/9/2018 |
0.2.0 | 710 | 11/24/2018 |
0.1.2-alpha | 628 | 11/14/2018 |
0.1.1-alpha | 556 | 11/8/2018 |
0.1.0-alpha | 582 | 11/6/2018 |
6.0.0:
* add .NET 9 support
* add .NET 8 support
* remove .NET 7 support
* System.Text.Json is used as default json framework
* use streams for i/o
* improve non ASCII symbol handling in "piped" mode (on Windows)
* remove dynamic
* bump version of dependencies
5.1.0:
* add RollForward property to allow installation on newer dotnet versions
5.0.0:
* remove --use-old-json-parser flag
* remove .NET Core 3.1 support
* bump version of dependencies
4.0.0:
* add --json-framework option (newtonsoft, system)
* add .NET 7 support
* remove .NET 5 support
* bump version of dependencies
3.0.1:
* fix: add .NET 6 support
* bump version of dependencies
3.0.0:
* add .NET 6 support
* remove .NET Core 2.1 support
* bump version of dependencies
2.2.0:
* simplified json parser
* improve json number handling (treat floating numbers as decimal)
* fix inconsistent date representation in simple value conversion
2.1.0:
* add net5.0 support
* bump version of dependencies
2.0.0:
* name output file based on last segment of url (if -u option is used and -o option is not provided)
* change default yaml null format (now null, was empty)
* remove dotnet core 2.2 and dotnet core 3.0 support
* add --skip-content-type-check flag
* fix issue when not all content of very huge file is written to file
* bump version of dependencies
1.3.0:
* add --format-null-as option
* fix parsing error when root level list contains null values
* bump version of dependencies
1.2.7:
* bump version of dependencies
1.2.6:
* file io opperations made async
1.2.5:
* fix incorrect recursion level handling in nested objects
1.2.4:
* better support for lists with mixed types in root level
1.2.3:
* bump versions of dependencies
1.2.2:
* add dotnet core 3.1 support
1.2.1:
* fix json2yaml throws error for null simple value
1.2.0:
* support simple value types in root (e.g. echo 5 | json2yaml -c)
1.1.0:
* support multiple runtimes: dotnet core 2.1, dotnet core 2.2, dotnet core 3.0
1.0.5:
* add -v|--verbose option. It shows more detailed errors
1.0.4:
* bump versions of dependencies
1.0.3:
* add --version option. It shows only version string
* fix incorrect message when -u|--url option value is missing
* fix incorrect message when -m|--max-size option value is missing
1.0.2:
* return error if json2yaml is run with no options in stdin mode (e.g. echo 5 | json2yaml)
1.0.1:
* bump versions of dependencies
* use MIT licence identifier in package
1.0.0:
* read input from redirected stdin. Full piping scenarious is supported
0.4.0:
* -c|--console-output: print output results directly to console
0.3.2:
* fix json2yaml -i throws when run on directory without any *.json file
* fix message when json size exceeds value provided with --max-size option
0.3.1:
* support array in root
0.3.0:
* -u|--url option to read input from http endpoint
* show tool version
0.2.0:
* -m|--max-size option
0.1.2-alpha:
* cleanup tool output to console
0.1.1-alpha:
* handle gracefully command line parsing errors