Giter VIP home page Giter VIP logo

json-cloak's Introduction

json-cloak

Replace UUIDs in your JSON files and JS objects with new UUIDs while preserving references.

json-cloak provides a command-line interface for transforming JSON files, as well as a function to use in JavaScript projects to transform individual JS objects. Identical UUIDs are replaced with the same UUID.

CLI Usage

Installation

The simplest way to use json-cloak is to invoke via npx:

npx json-cloak [options]

Alternatively, you can install json-cloak globally as a CLI:

# npm
npm install -g json-cloak

# yarn
yarn global add json-cloak

Note: The npm package name is json-cloak, however the globally installed binary name is just cloak

Command

cloak [options]

Options

  • -f, --file: Specify the JSON file to transform.
  • -i, --in-place: Update the file in place with the transformed JSON object.
  • -k, --keys: Display the replaced keys instead of printing the transformed JSON object.
  • -v, --version: Display the version number.
  • -p, --pattern: Specify a glob pattern to operate on multiple files. This will perform updates in place!
  • -q, --quiet: Don't print to stdout
  • -h, --help: Show the help message.

Examples

  1. Update the JSON file in place with the transformed content:
cloak -i -f data.json
  1. Display the keys that would be replaced for the given JSON file:
cloak -k -f data.json
  1. Use a glob pattern to transform multiple files (in place transformation only):
cloak -p 'test/*.json' -f other/dir/foo.json
  1. Display version info:
cloak -v

Library Usage

In addition to being used as a CLI, json-cloak can also be used inside JavaScript projects to transform individual JSON objects. Use either as CommonJS or ES6 module.

Installation

npm install json-cloak

or

yarn add json-cloak

Example

// CommonJS
// const { cloak } = require('json-cloak')

// ES6
import { cloak } from 'json-cloak'

const user = {
  id: 'a025c322-78af-4a23-8c27-e05a42be620e',
  name: 'Javier',
  age: 30,
  friends: [
    {
      id: '80b96ced-ad77-4a9a-b758-a04e5988d093',
      name: 'Sam',
      age: 35,
      friends: [
        {
          id: 'a025c322-78af-4a23-8c27-e05a42be620e',
          name: 'Javier',
          age: 30,
        } 
      ]
    } 
  ]
}

const transformedObject = cloak(user)

console.log(JSON.stringify(transformedObject, null, 2))
// {
//   "id": "08cb9bb4-65b4-4706-88ef-97f97d208b37",
//   "name": "Javier",
//   "age": 30,
//   "friends": [
//     {
//       "id": "6864205d-fcb2-49be-9c97-133379670e1a",
//       "name": "Sam",
//       "age": 35,
//       "friends": [
//         {
//           "id": "08cb9bb4-65b4-4706-88ef-97f97d208b37",
//           "name": "Javier",
//           "age": 30
//         }
//       ]
//     }
//   ]
// }

Contributing

Contributions are welcome, please open an issue or submit a pull request!


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.