Socket
Book a DemoInstallSign in
Socket

@pixelguild/json-utils

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixelguild/json-utils

This library provides utility functions for working with JSON data, including mapping and flattening JSON objects, and converting JSON data to CSV format.

latest
npmnpm
Version
1.0.92
Version published
Maintainers
1
Created
Source

JsonUtils

This library provides utility functions for working with JSON data, including mapping and flattening JSON objects, and converting JSON data to CSV format.

Installation

npm i @pixelguild/json-utils

Usage

mapJsonKeys

import { JsonUtils } from "@pixelguild/json-utils";

const json = {
  firstName: "John",
  lastName: "Doe",
  age: 30,
};

const keyMapping = {
  firstName: "first_name",
  lastName: "last_name",
};

const mappedJson = JsonUtils.mapJsonKeys(json, keyMapping);
console.log(mappedJson);

flattenJson

import { JsonUtils } from "@pixelguild/json-utils";

const json = {
  name: {
    first: "John",
    last: "Doe",
  },
  age: 30,
};

const flatJson = JsonUtils.flattenJson(json);
console.log(flatJson);

jsonToCsv

import { JsonUtils } from "@pixelguild/json-utils";

const json = [
  {
    firstName: "John",
    lastName: "Doe",
    age: 30,
  },
  {
    firstName: "Jane",
    lastName: "Doe",
    age: 28,
  },
];

const csv = JsonUtils.jsonToCsv(json);
console.log(csv);

jsonToCsv (with options)

import { JsonUtils } from "./JsonUtils";

const json = [
  {
    firstName: "John",
    lastName: "Doe",
    age: 30,
  },
  {
    firstName: "Jane",
    lastName: "Doe",
    age: 28,
  },
];

const options = {
  includeFields: ["firstName", "age"],
};

const csv = JsonUtils.jsonToCsv(json, options);
console.log(csv);

Keywords

json

FAQs

Package last updated on 10 Apr 2023

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