summaryrefslogtreecommitdiff
path: root/src/tools/jsontool.cpp
blob: 4b6f232d66f8547d54db13879de3ba9386c78979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bu/sio.h>
#include <bu/json.h>
#include <bu/file.h>

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("<invalid>");
            break;

        case Bu::Json::Object:
            Bu::println("<object>");
            {
                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("<array>");
            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("<null>");
            break;
    }
}

int main( int argc, char *argv[] )
{
    Bu::Json j;
    j.parse( Bu::File( argv[1], Bu::File::Read ).readAll() );

    printThing( j );

    return 0;
}