test_json.cpp raw

   1  // Copyright 2014 BitPay Inc.
   2  // Copyright (c) 2017-present The Bitcoin Core developers
   3  // Distributed under the MIT software license, see the accompanying
   4  // file COPYING or https://opensource.org/license/mit.
   5  
   6  // Test program that can be called by the JSON test suite at
   7  // https://github.com/nst/JSONTestSuite.
   8  //
   9  // It reads JSON input from stdin and exits with code 0 if it can be parsed
  10  // successfully. It also pretty prints the parsed JSON value to stdout.
  11  
  12  #include <univalue.h>
  13  
  14  #include <iostream>
  15  #include <iterator>
  16  #include <string>
  17  
  18  using namespace std;
  19  
  20  int main (int argc, char *argv[])
  21  {
  22      UniValue val;
  23      if (val.read(string(istreambuf_iterator<char>(cin),
  24                          istreambuf_iterator<char>()))) {
  25          cout << val.write(1 /* prettyIndent */, 4 /* indentLevel */) << endl;
  26          return 0;
  27      } else {
  28          cerr << "JSON Parse Error." << endl;
  29          return 1;
  30      }
  31  }
  32