Skip to content

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

License

Notifications You must be signed in to change notification settings

lmammino/json-dynamo-putrequest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published