diff options
Diffstat (limited to 'src/tools')
| -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 | |||
