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

yaml-to-json-converter

v11.0.15

Published

A simple utility to convert deeply nested YAML files OR yaml contents to JSON objects

Downloads

86

Readme

yaml-to-json-converter

A simple utility to convert deeply nested YAML files to JSON objects, below example is a 7 deep level YAML file.

YAML-to-JSON Converter is a versatile utility designed to transform single, double or deeply nested YAML files into JSON objects effortlessly. This tool accommodates any level of nested YAML structures, ensuring there are no depth restrictions. Users can either input a YAML file or provide hardcoded YAML strings for conversion, both examples are given below.

The utility guarantees seamless handling of complex YAML hierarchies, making it ideal for developers and data engineers. Whether you are dealing with configuration files, data serialization, or any YAML-based data format, this converter provides a reliable solution. Simplify your data transformation needs with our YAML-to-JSON Converter and enjoy the flexibility and ease it brings to your workflow.

Installation

npm install yaml-to-json-converter

Example Usage Code from client repo considering deeply-nested.yaml file below as a source yaml contents

    
const {readYamlFile} = require("yaml-to-json-converter");

const filePath = "deeply-nested.yaml";
const jsonData = readYamlFile(filePath);

console.log(JSON.stringify(jsonData, null, 2));

if (jsonData) {
  const dbHost = jsonData.app.database.host;
  console.log("Database Host:", dbHost);

  console.log(
    "Database credentials username :",
    jsonData.app.database.credentials.username
  );

  console.log(
    "UNDEFINED exampel services auth URL => :",
    jsonData.app.services.auth.url.sdf
  );
}

Example on reading direct YAML contents

const { readYamlContents} = require("yaml-to-json-converter");


const yamlContents = 
`app:
  name: MyApp
  version: 1.0.0
  environment: production
  database:
    host: localhost
    port: 5432
    name: myapp_db
    credentials:
      username: user123
      password: pass123
`;
//reading through contents 
const jsonData2 = readYamlContents(yamlContents);

console.log(
    "\n Direct Content Reading example app-> environment ",
    jsonData2.app.environment
  );

console.log(
    "\n Direct Content Reading example app-> database -> credentials -> username :",
    jsonData2.app.database.credentials.username
  );

console.log(
    "\n Direct Content Reading example app-> database -> credentials -> password :",
    jsonData2.app.database.credentials.password
  );

  console.log(
    "\n 2nd Example Showing app -> name :",
    jsonData2.app.name
  );  

deeply-nested.yaml file contents for reference


app: # 1st Level
  name: MyApp
  version: 1.0.0
  environment: production
  database: # 2nd  Level
    host: localhost # 3rd Level  Level
    port: 5432
    name: myapp_db
    credentials:
      username: user123
      password: pass123
  services: # 2nd  Level
    auth: # 3rd Level
      url: http://auth.myapp.com
      endpoints:
        login: /login
        register: /register
        logout: /logout
    user:  # 3rd Level
      url: http://user.myapp.com
      endpoints:
        profile: /profile
        settings: /settings
    payment: # 3rd Level
      url: http://payment.myapp.com
      endpoints: # 4th Level
        process: /process 
        status: /status
        statusdeep1: # 5th Level
          statusdeep1key: statusdeep1value
          statusdeep11: # 6th Level
            statusdeep111key: statusdeep111value # 7th Level

  features: # 2nd  Level
    - name: FeatureA
      enabled: true
      settings:
        option1: value1
        option2: value2
    - name: FeatureB
      enabled: false
      settings:
        option1: value1
        option2: value2


Image showing 7 levels YAML contents

Image showing Levels

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]