2019-12-27 10:28:18 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Helper functions for Json parsing
|
|
|
|
|
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2019-12-27 10:28:18 -05:00
|
|
|
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "Json.h"
|
2021-01-26 10:52:04 -05:00
|
|
|
#include "Exceptions.h"
|
2019-12-27 10:28:18 -05:00
|
|
|
|
|
|
|
|
const Json::Value openshot::stringToJson(const std::string value) {
|
|
|
|
|
|
|
|
|
|
// Parse JSON string into JSON objects
|
|
|
|
|
Json::Value root;
|
|
|
|
|
Json::CharReaderBuilder rbuilder;
|
|
|
|
|
Json::CharReader* reader(rbuilder.newCharReader());
|
|
|
|
|
|
|
|
|
|
std::string errors;
|
|
|
|
|
bool success = reader->parse( value.c_str(), value.c_str() + value.size(),
|
|
|
|
|
&root, &errors );
|
|
|
|
|
delete reader;
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
// Raise exception
|
|
|
|
|
throw openshot::InvalidJSON("JSON could not be parsed (or is invalid)");
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
}
|