aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2018-12-10 06:49:42 -0800
committerMike Buland <mbuland@penny-arcade.com>2018-12-10 06:49:42 -0800
commitfcfa8b28157a95a4cde6e656af6c6ce79cf548f0 (patch)
tree33a7b41424e1a61288f7e6f65b8806af15bece65
parentc9aefa91df23de57e57818840555171bf4c831a1 (diff)
downloadlibbu++-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.cpp65
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
5void 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
56int 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