1.0.92 • Published 2 years ago

@pixelguild/json-utils v1.0.92

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years 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

2 years ago

1.0.91

2 years ago

1.0.9

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago