Last active
August 29, 2015 14:07
-
-
Save iki/791c6cb046f3618e600f 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
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 |
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
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