Repository
Current version released
6 years ago
Versions
json2yaml
A Deno module that converts a JSON string to a (pretty) YAML string π¦
Inspired by https://github.com/alexcrist/json-to-pretty-yaml
Note: there already exists a module (
stringify()) 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:
import { json2yaml } from 'https://deno.land/x/json2yaml/mod.ts';
const jsonString = '{"hello": "world"}';
const yamlString = json2yaml(jsonString);
console.log(yamlString);Output:
hello: worldYou can also specify the number of spaces to use for indents:
const jsonString = '{"foo": ["bar", "baz"]}';
const yamlString = json2yaml(jsonString, 3);
console.log(yamlString);Output:
foo:
- bar
- bazFor more documentation, run:
$ deno doc mod.tsCLI
# 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.yamlYou can also use deno install to easily create an alias command:
$ deno install -f --allow-read -n json2yaml https://deno.land/x/json2yaml/cli.ts
# Much shorter!
$ json2yaml -- input.jsonExplanation:
-f: Forcefully overrides previous installations of json2yaml--allow-read: Grants read access to the cli-n json2yaml: Sets the alias to json2yaml
Testing
$ deno test --allow-read