Last active
February 22, 2016 15:23
-
-
Save TheCalorious/34224172428fb85002a8 to your computer and use it in GitHub Desktop.
A simple formatter to change Parse to dynamo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonfile = require('jsonfile'); | |
var fs = require('fs-extra'); | |
var moment = require('moment'); | |
var _ = require('lodash'); | |
var attr = require('dynamodb-data-types').AttributeValue; | |
var foodFile = "parse-data/food.json"; | |
var foodJson = jsonfile.readFileSync(foodFile); | |
var foodResults = foodJson.results; | |
var foods = []; | |
function loopy(){ | |
for(var i=0; i<foodResults.length; i++){ | |
var food = foodResults[i]; | |
food.createdAt = moment(food.createdAt).valueOf(); | |
food.user = food.user.objectId; | |
delete food.updatedAt; | |
delete food.objectId; | |
//uncomment below if you want json in dynamodb format | |
//foods.push(attr.wrap(food)); | |
foods.push(food); | |
} | |
} | |
loopy(); | |
var ws = fs.createOutputStream('data/foods.ddb.json') | |
ws.write(JSON.stringify(foods)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment