OpenShot Library | libopenshot  0.3.3
Json.cpp
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #include "Json.h"
14 #include "Exceptions.h"
15 
16 const Json::Value openshot::stringToJson(const std::string value) {
17 
18  // Parse JSON string into JSON objects
19  Json::Value root;
20  Json::CharReaderBuilder rbuilder;
21  Json::CharReader* reader(rbuilder.newCharReader());
22 
23  std::string errors;
24  bool success = reader->parse( value.c_str(), value.c_str() + value.size(),
25  &root, &errors );
26  delete reader;
27 
28  if (!success)
29  // Raise exception
30  throw openshot::InvalidJSON("JSON could not be parsed (or is invalid)");
31 
32  return root;
33 }
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:217
Json.h
Header file for JSON class.
Exceptions.h
Header file for all Exception classes.