🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@kishor82/jsonflat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kishor82/jsonflat

A lightweight JavaScript library to flatnested JSON objects into a single-level structure.

latest
Source
npmnpm
Version
0.1.0-beta.1
Version published
Weekly downloads
12
-73.91%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version Build status Coverage Status

jsonflat

jsonflat is a lightweight Node.js library that flattens nested JSON objects to a single level using customizable delimiters.

Installation

You can install jsonflat via npm:

npm install @kishor82/jsonflat

Usage

To flata nested JSON object, import the flat function from jsonflat and use it as follows:

const { flat } = require("@kishor82/jsonflat");

const nestedObject = {
  person: {
    name: {
      first: "John",
      last: "Doe",
    },
    age: 30,
    address: {
      city: "New York",
      state: "NY",
    },
  },
};

const flattenedObject = flat(nestedObject);

console.log(flattenedObject);

The flat function accepts an optional delimiter parameter to customize the separator used in the flattened keys:

const flattenedObject = flat(nestedObject, ".");

console.log(flattenedObject);

API

flat(inputObject, delimiter = '.')

Flattens the input JSON object to a single level.

  • inputObject (Object): The nested JSON object to be flattened.
  • delimiter (String): Optional. The delimiter used to separate keys in the flattened output. Default is '.'.

Returns: A new object with flattened keys.

Examples

flatNested JSON Object

const { flat } = require("@kishor82/jsonflat");

const nestedObject = {
  person: {
    name: {
      first: "John",
      last: "Doe",
    },
    age: 30,
    address: {
      city: "New York",
      state: "NY",
    },
  },
};

const flattenedObject = flat(nestedObject);

console.log(flattenedObject);

Output:

{
  "person.name.first": "John",
  "person.name.last": "Doe",
  "person.age": 30,
  "person.address.city": "New York",
  "person.address.state": "NY"
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

flat-json

FAQs

Package last updated on 09 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts