OpenShot Library | libopenshot  0.2.7
Json.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Helper functions for Json parsing
4  * @author FeRD (Frank Dana) <ferdnyc@gmail.com>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #include "Json.h"
32 #include "Exceptions.h"
33 
34 const Json::Value openshot::stringToJson(const std::string value) {
35 
36  // Parse JSON string into JSON objects
37  Json::Value root;
38  Json::CharReaderBuilder rbuilder;
39  Json::CharReader* reader(rbuilder.newCharReader());
40 
41  std::string errors;
42  bool success = reader->parse( value.c_str(), value.c_str() + value.size(),
43  &root, &errors );
44  delete reader;
45 
46  if (!success)
47  // Raise exception
48  throw openshot::InvalidJSON("JSON could not be parsed (or is invalid)");
49 
50  return root;
51 }
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:34
Header file for all Exception classes.
Header file for JSON class.
Exception for invalid JSON.
Definition: Exceptions.h:205