1.0.92 • Published 1 year ago

@pixelguild/json-utils v1.0.92

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

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

1 year ago

1.0.91

1 year ago

1.0.9

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago