Giter Club home page Giter Club logo

json-scrub's Introduction

json-scrub

Sanitize arbitrary JSON objects according to a configuration.

Quickstart

$ composer require bishopb/json-scrub
$ composer test

Using

There are two ways to use this code: library and command line.

Library

There are two library functions for use:

  1. ObjectScrub::scrubAll replaces the value of all instances of the given keys, regardless of where they appear in the given object.
  2. ObjectScrub::scrub replaces the value for all keys that match the path given, in dot notation. So foo.bar would replace the value "baz" in this: { "foo": { "bar": "baz" }, "foo.bar": "quux" }.

For example:

$scrubber = new \ObjectScrub();
$objects = $scrubber->scrub([ 'foo.bar' ], $objects, '***');
$objects = $scrubber->scrubAll([ 'foo' ], $objects, '***');

Refer to the tests/ directory for more example usages.

Command line usage

The command sanitize takes up to three arguments, as described in the built-in documentation:

$ ./sanitize -h
Scrub a file containing one or more JSON objects of sensitive values.

USAGE:
    sanitize [config='./config.json'] [objects='./objects.json'] [replace='***']

WHERE:
    config   Is a file describing the keys to be scrubbed. Defaults to
             './config.json'. See the config.json for a description of the file.
    objects  Is a file containing the objects to to be scrubbed. Keys in those
             objects matching keys in the config file will be replaced with the
             given replacement. Default is './objects.json'.
    replace  The string to replace matching keys with. Defaults to '***'.

OUTPUT:
    Outputs on standard out the scrubbed version of each JSON object from the
    given objects, each object separated by a newline. The original white space
    may not be preserved.

EXIT CODES:
    0 if everything is ok
    1 if incorrect arguments are given
    2 if the files pointed to by the arguments cannot be read
    3 if the files do not contain valid JSON
    4 if the configuration file does not have a recognized format

See the examples/ directory for some possible usages.

json-scrub's People

Contributors

bishopb avatar

Watchers

James Cloos avatar

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.