2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-25 19:30:04 +01:00
waf/playground/json/wscript
Matt Clarkson 6c485625f4 Added a JSON example to the playground
The example reads a file as JSON, adds a key, then writes the new structure
to a JSON file in the build folder. The example accepts a '--pretty'
argument to output human readable JSON to the file.
2015-11-20 13:53:39 +00:00

33 lines
621 B
Python

#! /usr/bin/env python
# encoding: utf-8
# Matt Clarkson, 2015 (ita)
VERSION='0.0.1'
APPNAME='json_test'
top = '.'
import sys
import waflib.Configure
waflib.Configure.autoconfig = True
def options(opt):
opt.add_option(
'--pretty',
action = 'store_true',
help = 'pretty prints the writing of the JSON')
def configure(conf):
pass
def build(bld):
node = bld.srcnode.make_node('test.json')
json = node.read_json()
print('Read', json)
json['new_key'] = {
'number': 199
}
output = bld.bldnode.make_node('output.json')
output.write_json(json, pretty=bld.options.pretty)
print('Wrote', output.read())