aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/json_parse.cc
blob: a2f004f5a5f8792968bb099afe440fb0032b3687 (plain) (blame)
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
#include <qpdf/JSON.hh>
#include <qpdf/QUtil.hh>
#include <iostream>

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: json_parse file" << std::endl;
        return 2;
    }
    char const* filename = argv[1];
    try
    {
        PointerHolder<char> buf;
        size_t size;
        QUtil::read_file_into_memory(filename, buf, size);
        std::string s(buf.get(), size);
        std::cout << JSON::parse(s).unparse() << std::endl;
    }
    catch (std::exception& e)
    {
        std::cerr << "exception: " << filename<< ": " << e.what() << std::endl;
        return 2;
    }
    return 0;
}