npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quick-jsonify

v1.2.0

Published

A versatile JSON utility package with features like jsonify, xmlToJson, masking, validation, flattening, transformation, and more.

Downloads

16

Readme

Quick-JSONify

A simple yet powerful JSON utility package for Node.js, providing features like JSON formatting, xml To json, key transformation, validation, masking, and more.

Installation

npm install quick-jsonify

Features

  1. jsonify - Convert an object to a JSON string with customizable options.
  2. getSummary - Get a summary of the JSON data structure.
  3. validate - Validate JSON data against a schema.
  4. sortObjectKeys - Sort the keys of a JSON object.
  5. flattenObject - Flatten a nested JSON object.
  6. unflattenObject - Unflatten a flattened JSON object.
  7. deepClone - Create a deep clone of a JSON object.
  8. prettyPrint - Print a JSON object in a formatted way with optional highlights.
  9. transformValues - Transform values in a JSON object using a custom function.
  10. transformKeys - Transform the keys of a JSON object (e.g., camelCase).
  11. mergeJsonObjects - Merge multiple JSON objects into one.
  12. filterJsonKeys - Filter a JSON object to include only specified keys.
  13. generateSampleJson - Generate a sample JSON object with specified keys.
  14. jsonToXml - Convert a JSON object to an XML string.
  15. deepFreeze - Make a JSON object immutable.
  16. maskSensitiveData - Mask sensitive data in a JSON object.
  17. addCommentsToJson - Add comments to a JSON object.

Usage/Example

1. jsonify
Convert an object to a JSON string with customizable options.

const { jsonify } = require('quick-jsonify');

const data = { name: "John", age: 30, city: "New York" };
const options = { indent: 2, highlight: true };

console.log(jsonify(data, options));

2. getSummary
Get a summary of the JSON data structure.

const { getSummary } = require('quick-jsonify');

const data = { name: "John", age: 30, city: "New York" };
console.log(getSummary(data));
// Output: { type: 'object', properties: 3 }

3. validate
Validate JSON data against a schema.

const { validate } = require('quick-jsonify');

const data = { name: "John", age: "30" };
const schema = { name: "string", age: "number" };

console.log(validate(data, schema));
// Output: { valid: false, errors: [{ key: 'age', expectedType: 'number', actualType: 'string' }] }

4. sortObjectKeys
Sort the keys of a JSON object.

const { sortObjectKeys } = require('quick-jsonify');

const data = { b: 2, a: 1, c: 3 };
console.log(sortObjectKeys(data));
// Output: { a: 1, b: 2, c: 3 }

5. flattenObject
Flatten a nested JSON object.

const { flattenObject } = require('quick-jsonify');

const data = { a: { b: { c: 1 } } };
console.log(flattenObject(data));
// Output: { 'a.b.c': 1 }

6. unflattenObject
Unflatten a flattened JSON object.

const { unflattenObject } = require('quick-jsonify');

const data = { 'a.b.c': 1 };
console.log(unflattenObject(data));
// Output: { a: { b: { c: 1 } } }

7. deepClone
Create a deep clone of a JSON object.

const { deepClone } = require('quick-jsonify');

const data = { name: "John", age: 30 };
const clone = deepClone(data);
clone.name = "Jane";

console.log(data.name); // Output: John
console.log(clone.name); // Output: Jane

8. prettyPrint
Print a JSON object in a formatted way with optional highlights.

const { prettyPrint } = require('quick-jsonify');

const data = { name: "John", age: 30 };
prettyPrint(data);

9. transformValues
Transform values in a JSON object using a custom function.

const { transformValues } = require('quick-jsonify');

const data = { name: "John", age: 30 };
const transformed = transformValues(data, value => (typeof value === "number" ? value * 2 : value));

console.log(transformed); // Output: { name: "John", age: 60 }

10. transformKeys
Transform the keys of a JSON object (e.g., to camelCase).

const { transformKeys } = require('quick-jsonify');

const data = { "first_name": "John", "last_name": "Doe" };
const transformed = transformKeys(data, "camelCase");

console.log(transformed); // Output: { firstName: "John", lastName: "Doe" }

11. mergeJsonObjects
Merge multiple JSON objects into one.

const { mergeJsonObjects } = require('quick-jsonify');

const obj1 = { a: 1 };
const obj2 = { b: 2 };
console.log(mergeJsonObjects(obj1, obj2));
// Output: { a: 1, b: 2 }

12. filterJsonKeys
Filter a JSON object to include only specified keys.

const { filterJsonKeys } = require('quick-jsonify');

const data = { name: "John", age: 30, city: "New York" };
console.log(filterJsonKeys(data, ["name", "city"]));
// Output: { name: "John", city: "New York" }

13. generateSampleJson
Generate a sample JSON object with specified keys.

const { generateSampleJson } = require('quick-jsonify');

console.log(generateSampleJson(["name", "age"], "default"));
// Output: { name: "default", age: "default" }

14. jsonToXml
Convert a JSON object to an XML string.

const { jsonToXml } = require('quick-jsonify');

const data = { name: "John", age: 30 };
console.log(jsonToXml(data));
// Output: <name>John</name><age>30</age>

15. deepFreeze
Make a JSON object immutable.

const { deepFreeze } = require('quick-jsonify');

const data = { name: "John", age: 30 };
deepFreeze(data);

data.age = 40; // This won't change the value
console.log(data.age); // Output: 30

16. maskSensitiveData
Mask sensitive data in a JSON object.

const { maskSensitiveData } = require('quick-jsonify');

const data = { name: "John", password: "secret" };
console.log(maskSensitiveData(data, ["password"]));
// Output: { name: "John", password: "***" }

17. addCommentsToJson
Add comments to a JSON object.

const { addCommentsToJson } = require('quick-jsonify');

const data = { name: "John", age: 30 };
const comments = { age: "Age in years" };

console.log(addCommentsToJson(data, comments, 2));
// Output: 
// {
//   "name": "John",
//   "age": 30 // Age in years
// }

License

This package is open-source and licensed under the MIT License.