5 #ifndef GKO_PUBLIC_EXTENSIONS_CONFIG_JSON_CONFIG_HPP_
6 #define GKO_PUBLIC_EXTENSIONS_CONFIG_JSON_CONFIG_HPP_
13 #include <nlohmann/json.hpp>
15 #include <ginkgo/core/config/property_tree.hpp>
29 const auto& dom = input;
31 auto parse_array = [](
const auto& arr) {
32 gko::config::pnode::array_type nodes;
34 nodes.emplace_back(parse_json(it));
38 auto parse_map = [](
const auto& map) {
39 gko::config::pnode::map_type nodes;
40 for (
auto& el : map.items()) {
41 nodes.emplace(el.key(), parse_json(el.value()));
45 auto parse_data = [](
const auto& data) {
46 if (data.is_number_integer()) {
49 if (data.is_boolean()) {
52 if (data.is_number_float()) {
55 if (data.is_string()) {
57 std::string(data.template get<std::string>())};
59 throw std::runtime_error(
60 "property_tree can not handle the node with content: " +
65 return parse_array(dom);
67 if (dom.is_object()) {
68 return parse_map(dom);
70 return parse_data(dom);
79 std::ifstream fstream(filename);
80 return parse_json(nlohmann::json::parse(fstream));
88 return parse_json(nlohmann::json::parse(json));
96 #endif // GKO_PUBLIC_EXTENSIONS_CONFIG_JSON_CONFIG_HPP_