Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fs = require 'fs'
log = console.log
dump = (obj) -> JSON.stringify obj, null, 2
keys = Object.keys
src = process.argv[2] or 'package.json'
log src
pkg = JSON.parse fs.readFileSync src
log 'JSON: ' + dump pkg
log 'Keys: ' + keys pkg
pkg.version = '0.0.1'
log 'JSON: ' + dump pkg
log 'Keys: ' + keys pkg
pkg.newattr = 1
log 'JSON: ' + dump pkg
log 'Keys: ' + keys pkg
import sys
import json
log = lambda line: sys.stdout.write(line + "\n")
dump = lambda obj: json.dumps(obj, indent=2)
keys = lambda obj: str(obj.keys())
src = len(sys.argv) > 1 and sys.argv[1] or 'package.json'
log(src)
pkg = json.load(file(src))
log('JSON: ' + dump(pkg))
log('Keys: ' + keys(pkg))
pkg['version'] = '0.0.1'
log('JSON: ' + dump(pkg))
log('Keys: ' + keys(pkg))
pkg['newattr'] = 1
log('JSON: ' + dump(pkg))
log('Keys: ' + keys(pkg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.