npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-to-yaml-converter

v1.0.5

Published

A simple utility to convert JSON Objects or json files to yaml contents

Downloads

29

Readme

JSON to YAML Converter

json-to-yaml-converter A simple yet powerful utility for converting JSON objects / JSON files to YAML format. This package provides an easy way to read JSON content from an object file and convert it into a human-readable YAML format. The converted YAML can also be saved to an output file if specified.

Features:

Convert JSON to YAML: Read JSON content from a file or from json object and convert it to YAML format.

Optional File Output: Save the converted YAML content to a specified output file.

Easy Integration: Simple API for seamless integration into your projects.

Example Usage:

Installation

npm install json-to-yaml-converter

Direct JSON Code Example 1

Example 1


const { jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

//single level
const json = {
  name: 'MyApp',
  version: '1.0.0',
  description: 'An example app'
};

const yamlString = jsonToYaml(json);
console.log(yamlString);

Output 1


name: MyApp
version: 1.0.0
description: An example app

Direct JSON Code Example 2

Example 2


const { jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

//two level 
const json =  {
    "app": {
        "name": "MyApp",
        "version": "1.0.0",
        "description": "An example app"
    }
}

const yamlString = jsonToYaml(json);
console.log(yamlString);

Output 2

app:
  name: MyApp
  version: 1.0.0
  description: An example app

Direct JSON Code Example 3

Example 3


const { jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

//three level 
const json =  {
    "app": {
        "name": "MyApp",
        "version": "1.0.0",
        "description": "An example app",
        "database": {
            "host": "localhost",
            "port": 5432,
            "name": "myapp_db"
        }
    }
}

const yamlString = jsonToYaml(json);
console.log(yamlString);

Output 3

app:
  name: MyApp
  version: 1.0.0
  description: An example app
  database:
    host: localhost
    port: 5432
    name: myapp_db

Code Example (read from json file)

input JSON file name is 'example.json'

output YAML file name is 'output.yaml'


const { jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

// Convert JSON to YAML and save to output.yaml
const yamlString = convertJsonFileToYaml('./example.json', './output.yaml');

if (yamlString) {
  console.log('YAML content:');
  console.log(yamlString);
}

Example 2

input JSON file name is 'sample1.json'

output YAML file name is 'output1.yaml'


const { jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

const yamlString = convertJsonFileToYaml('./sample1.json', 'output1.yaml');

if (yamlString) {
  console.log(yamlString);
}

Example 3

input JSON file name is 'sample2.json'

output YAML file name is 'output2.yaml'


const {jsonToYaml, convertJsonFileToYaml } = require('json-to-yaml-converter');

const yamlString = convertJsonFileToYaml('./sample2.json', 'output2.yaml');

if (yamlString) {
  console.log(yamlString);
}

Proprietary License


All rights reserved.

This software and its source code are the property of myself i.e. Sampurna Atmaramani. Unauthorized copying, modification, distribution, or use of this software, via any medium, is strictly prohibited. 

For inquiries regarding the use of this software, please contact [email protected]