Forked from levelsio/Building an MVP? Need a quick DB? Use JSON!
Last active
September 12, 2017 22:47
-
-
Save rosswd/45971a28bd913cf4712c6a1837d454c7 to your computer and use it in GitHub Desktop.
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
# | |
# 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