Convert from YAML to Jsonnet format, retaining comments
Project description
YAML2Jsonnet: Switch configuration languages
Converts YAML into Jsonnet (specifically targetting YAML for Kubernetes)
Suppose that you have some YAML that you use for Kubernetes (either hand-written or output by Helm. Now you'd like to use Jsonnet instead, for its fancier templating capabilities. This is a pain, because while YAML->JSON converters are easy to find, they produce ugly-looking (but valid!) Jsonnet.
YAML2Jsonnet makes the conversion a little easier: it transforms the YAML into slightly prettier Jsonnet, preserving comments along the way.
Example
A trivial YAML document:
---
# simple example
- hello: world
one: 1
Convert it to Jsonnet:
$ yaml2jsonnet trivial.yaml | jsonnetfmt - -o trivial.jsonnet
(Note that we run the output of yaml2jsonnet through the jsonnet formatter jsonnetfmt
. This is strongly recommended, since the
raw output of yaml2jsonnet is quite ugly.)
The result:
[
// simple example
{
hello: 'world',
one: 1,
},
]
Installing
Yaml2Jsonnet expects Python 3.6 or above.
pip install yaml2jsonnet
Or, as this is meant as a stand-alone tool, you may prefer
pipx install yaml2jsonnet
Development
- Install Poetry
- Install Pre-commit
- Run
poetry install
to install dependencies - Run
poetry run python -m yaml2jsonnet /path/to/yaml
to convert a file - Probably, run
jsonnetfmt
on the output, since the only whitespace I provide is newlines
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yaml2jsonnet-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7af7ae431543a837600e8e21fbc8740ea3011ab1c8c543282e61142f9790255b |
|
MD5 | 74254812f246f0f12e8e33ed437cfda1 |
|
BLAKE2b-256 | ef8d475b5c707a5191f69c997b2e9425405b9dcfadb75bccc324d8bbbe4f5e91 |