@pixelguild/json-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.92 • Public • Published

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);

Readme

Keywords

Package Sidebar

Install

npm i @pixelguild/json-utils

Weekly Downloads

2

Version

1.0.92

License

MIT

Unpacked Size

18.3 kB

Total Files

17

Last publish

Collaborators

  • tylerqueen