https://github.com/rikilele/json2yaml
A Deno module that converts a JSON string to a (pretty) YAML string 🦕
https://github.com/rikilele/json2yaml
deno json json2yaml yaml
Last synced: 2 months ago
JSON representation
A Deno module that converts a JSON string to a (pretty) YAML string 🦕
- Host: GitHub
- URL: https://github.com/rikilele/json2yaml
- Owner: rikilele
- License: mit
- Created: 2020-07-15T14:40:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-12T12:08:01.000Z (almost 5 years ago)
- Last Synced: 2025-02-17T19:05:11.836Z (over 1 year ago)
- Topics: deno, json, json2yaml, yaml
- Language: TypeScript
- Homepage: https://deno.land/x/json2yaml
- Size: 46.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json2yaml
A Deno module that converts a JSON string to a (pretty) YAML string 🦕

[](https://nest.land/package/json2yaml)
_Inspired by https://github.com/alexcrist/json-to-pretty-yaml_
> **Note**: there already exists a module
> ([`stringify()`](https://deno.land/std/encoding/#yaml)) to convert JavaScript
> objects to YAML strings in the Deno standard library. Consider using this
> instead if you prefer working with JavaScript objects!
## Module
Basic usage:
```js
import { json2yaml } from "https://deno.land/x/json2yaml/mod.ts";
const jsonString = '{"hello": "world"}';
const yamlString = json2yaml(jsonString);
console.log(yamlString);
```
Output:
```yaml
hello: world
```
You can also specify the number of spaces to use for indents:
```js
const jsonString = '{"foo": ["bar", "baz"]}';
const yamlString = json2yaml(jsonString, 3);
console.log(yamlString);
```
Output:
```yaml
foo:
- bar
- baz
```
For more documentation, run:
```sh
$ deno doc mod.ts
```
## CLI
```sh
# Prints output to stdout
$ deno run --allow-read https://deno.land/x/json2yaml/cli.ts -- input.json
# Write contents into output.yaml
$ deno run --allow-read https://deno.land/x/json2yaml/cli.ts -- input.json > output.yaml
```
You can also use `deno install` to easily create an alias command:
```sh
$ deno install -f --allow-read -n json2yaml https://deno.land/x/json2yaml/cli.ts
# Much shorter!
$ json2yaml -- input.json
```
Explanation:
- `-f`: Forcefully overrides previous installations of json2yaml
- `--allow-read`: Grants read access to the cli
- `-n json2yaml`: Sets the alias to json2yaml
## Testing
```sh
$ deno test --allow-read
```