From fcfa8b28157a95a4cde6e656af6c6ce79cf548f0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 10 Dec 2018 06:49:42 -0800 Subject: Added a tool for testing & manipulating json. Probably do more with it later. --- src/tools/jsontool.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/tools/jsontool.cpp (limited to 'src') 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 @@ +#include +#include +#include + +void printThing( Bu::Json &j, int iDepth=0 ) +{ + for(int i = 0; i < iDepth; i++ ) + Bu::print(" "); + + switch( j.getType() ) + { + case Bu::Json::Invalid: + Bu::println(""); + break; + + case Bu::Json::Object: + Bu::println(""); + { + Bu::StringList lKeys = j.getKeys(); + for( Bu::StringList::iterator i = lKeys.begin(); i; i++ ) + { + for(int k = 0; k < iDepth+1; k++ ) + Bu::print(" "); + Bu::println("'%1':").arg( *i ); + printThing( j[*i], iDepth+2 ); + } + } + break; + + case Bu::Json::Array: + Bu::println(""); + for( int i = 0; i < j.getSize(); i++ ) + { + printThing( j[i], iDepth+1 ); + } + break; + + case Bu::Json::String: + Bu::println("'%1'").arg( j.getString() ); + break; + + case Bu::Json::Number: + Bu::println("%1").arg( j.getNumber() ); + break; + + case Bu::Json::Boolean: + Bu::println("%1").arg( j.getBoolean() ); + break; + + case Bu::Json::Null: + Bu::println(""); + break; + } +} + +int main( int argc, char *argv[] ) +{ + Bu::Json j; + j.parse( Bu::File( argv[1], Bu::File::Read ).readAll() ); + + printThing( j ); + + return 0; +} + -- cgit v1.2.3