Coder Social home page Coder Social logo

gitlabbin / json-dynamo-putrequest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lmammino/json-dynamo-putrequest

0.0 1.0 0.0 76 KB

Converts an arbitrary JSON into a DynamoDB PutRequest JSON to simplify the import of the raw data

License: MIT License

JavaScript 100.00%

json-dynamo-putrequest's Introduction

json-dynamo-putrequest

npm version CircleCI JavaScript Style Guide

Converts an arbitrary JSON into a DynamoDB PutRequest JSON to simplify the import of the raw data

The command basically takes a JSON string defining an array of objects as input and it converts to a JSON that contains an array of PutRequests suitable for loading the data in the original file in DynamoDB.

As an example if you have the following integers.json file as input:

[
  { "value": 1 },
  { "value": 2 }
]

and you run:

json-dynamo-putrequest integersTable integers.json --beautify

It will output:

{
  "integersTable": [
    {
      "PutRequest": {
        "Item": {
          "value": {
            "N": "1"
          }
        }
      }
    },
    {
      "PutRequest": {
        "Item": {
          "value": {
            "N": "2"
          }
        }
      }
    }
  ]
}

If you save this output in a file called integersDynamo.json you can then import the data directly in DynamoDB using the AWS command line client:

aws dynamodb batch-write-item --request-items file://integersDynamo.json

Install

Globally:

npm install --global json-dynamo-putrequest

Or as a dev dependency (e.g. you need it as part of your build process)

npm install --save-dev json-dynamo-putrequest

Usage

Using "pipes":

cat some.json | json-dynamo-putrequest tableName

Using input redirection:

json-dynamo-putrequest tableName < some.json

If you want to save the output to a file just use output redirection (or the --output option):

json-dynamo-putrequest tableName < some.json > dynamo.json
# OR json-dynamo-putrequest tableName --output dynamo.json < some.json

If you prefer to read the input from a file (rather then from the standard input) you can pass an extra parameter instead of using pipes or input redirection:

json-dynamo-putrequest tableName some.json

You can also beautify the output using the --beautify flag:

json-dynamo-putrequest --beautify tableName some.json

PRO-TIP: if you don't want to write json-dynamo-putrequest all the time, there is also the abbreviated alias jdp! :)

Command line options

You can display the live help by running:

json-dynamo-putrequest --help

Which will give you the list of all the available options and arguments:

json-dynamo-putrequest <tableName> [sourceFile]

Converts a JSON input into a JSON containing a set of DynamoDB PutRequests

Positionals:
  tableName   The name of the DynamoDB table                            [string]
  sourceFile  The source JSON file. If not specified the data will be read from
              the standard input                                        [string]

Options:
  --help          Show help                                            [boolean]
  --output, -o    the output file, if specified the output will be written in
                  the file
  --beautify, -b  the output file, if specified the output will be written in
                  the file                                             [boolean]
  --version       Show version number                                  [boolean]

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

License

Licensed under MIT License. © Luciano Mammino.

json-dynamo-putrequest's People

Contributors

lmammino avatar

Watchers

 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.