11.0.15 • Published 1 year ago

yaml-to-json-converter v11.0.15

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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 s.atmaramani@gmail.com 
11.0.15

1 year ago

11.0.13

1 year ago

11.0.12

1 year ago

11.0.11

1 year ago

11.0.10

1 year ago

11.0.9

1 year ago

11.0.8

1 year ago

11.0.7

1 year ago

11.0.6

1 year ago

11.0.5

1 year ago

11.0.4

1 year ago

11.0.2

1 year ago

11.0.1

1 year ago

11.0.0

1 year ago

10.0.0

1 year ago

9.0.0

1 year ago

8.0.0

1 year ago

7.0.0

1 year ago

6.0.0

1 year ago

5.0.0

1 year ago

4.0.0

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago