Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rosswd/45971a28bd913cf4712c6a1837d454c7 to your computer and use it in GitHub Desktop.
Save rosswd/45971a28bd913cf4712c6a1837d454c7 to your computer and use it in GitHub Desktop.
#
# Building an MVP?
# Need a quick database you can set up in seconds?
# What about JSON?
#
# by @levelsio (with help from @marckohlbrugge, @oskarth, @maxdeviant and @kumailht)
# JS
db=[]
fs=require('fs')
fs.writeFileSync('db', JSON.stringify(db))
db=JSON.parse(fs.readFileSync('db'),'utf8')
# PHP #
$db=array();
file_put_contents('db',json_encode($db));
$db=json_decode(file_get_contents('db'),true);
# Ruby #
require "json"
db=[]
File.write "db.json", db.to_json
db=JSON.parse open("db.json").read
# Python #
import json
db={}
db['thing']=[]
db['thing'].append({'id': 4123, 'color': 'green'})
with open('db.json', 'w') as outfile:
json.dump(db, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment