mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-25 03:09:30 +01:00
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.
This commit is contained in:
parent
8b71e16989
commit
6c485625f4
9
playground/json/test.json
Normal file
9
playground/json/test.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"array": [1, 2, "abc", 4.8, null],
|
||||
"dict": {
|
||||
"integer": 1,
|
||||
"float": 4.8,
|
||||
"string": "Hello, world!"
|
||||
},
|
||||
"boolean": true
|
||||
}
|
32
playground/json/wscript
Normal file
32
playground/json/wscript
Normal file
@ -0,0 +1,32 @@
|
||||
#! /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())
|
Loading…
Reference in New Issue
Block a user