diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2018-12-10 06:49:42 -0800 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2018-12-10 06:49:42 -0800 |
commit | fcfa8b28157a95a4cde6e656af6c6ce79cf548f0 (patch) | |
tree | 33a7b41424e1a61288f7e6f65b8806af15bece65 /src | |
parent | c9aefa91df23de57e57818840555171bf4c831a1 (diff) | |
download | libbu++-fcfa8b28157a95a4cde6e656af6c6ce79cf548f0.tar.gz libbu++-fcfa8b28157a95a4cde6e656af6c6ce79cf548f0.tar.bz2 libbu++-fcfa8b28157a95a4cde6e656af6c6ce79cf548f0.tar.xz libbu++-fcfa8b28157a95a4cde6e656af6c6ce79cf548f0.zip |
Added a tool for testing & manipulating json.
Probably do more with it later.
Diffstat (limited to '')
-rw-r--r-- | src/tools/jsontool.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/tools/jsontool.cpp b/src/tools/jsontool.cpp new file mode 100644 index 0000000..4b6f232 --- /dev/null +++ b/src/tools/jsontool.cpp | |||
@@ -0,0 +1,65 @@ | |||
1 | #include <bu/sio.h> | ||
2 | #include <bu/json.h> | ||
3 | #include <bu/file.h> | ||
4 | |||
5 | void printThing( Bu::Json &j, int iDepth=0 ) | ||
6 | { | ||
7 | for(int i = 0; i < iDepth; i++ ) | ||
8 | Bu::print(" "); | ||
9 | |||
10 | switch( j.getType() ) | ||
11 | { | ||
12 | case Bu::Json::Invalid: | ||
13 | Bu::println("<invalid>"); | ||
14 | break; | ||
15 | |||
16 | case Bu::Json::Object: | ||
17 | Bu::println("<object>"); | ||
18 | { | ||
19 | Bu::StringList lKeys = j.getKeys(); | ||
20 | for( Bu::StringList::iterator i = lKeys.begin(); i; i++ ) | ||
21 | { | ||
22 | for(int k = 0; k < iDepth+1; k++ ) | ||
23 | Bu::print(" "); | ||
24 | Bu::println("'%1':").arg( *i ); | ||
25 | printThing( j[*i], iDepth+2 ); | ||
26 | } | ||
27 | } | ||
28 | break; | ||
29 | |||
30 | case Bu::Json::Array: | ||
31 | Bu::println("<array>"); | ||
32 | for( int i = 0; i < j.getSize(); i++ ) | ||
33 | { | ||
34 | printThing( j[i], iDepth+1 ); | ||
35 | } | ||
36 | break; | ||
37 | |||
38 | case Bu::Json::String: | ||
39 | Bu::println("'%1'").arg( j.getString() ); | ||
40 | break; | ||
41 | |||
42 | case Bu::Json::Number: | ||
43 | Bu::println("%1").arg( j.getNumber() ); | ||
44 | break; | ||
45 | |||
46 | case Bu::Json::Boolean: | ||
47 | Bu::println("%1").arg( j.getBoolean() ); | ||
48 | break; | ||
49 | |||
50 | case Bu::Json::Null: | ||
51 | Bu::println("<null>"); | ||
52 | break; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | int main( int argc, char *argv[] ) | ||
57 | { | ||
58 | Bu::Json j; | ||
59 | j.parse( Bu::File( argv[1], Bu::File::Read ).readAll() ); | ||
60 | |||
61 | printThing( j ); | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||