#pragma once #include #include using nlohmann::json; namespace llarp::rpc { inline oxenc::bt_value json_to_bt(json&& j) { if (j.is_object()) { oxenc::bt_dict res; for (auto& [k, v] : j.items()) { if (v.is_null()) continue; // skip k-v pairs with a null v (for other nulls we fail). res[k] = json_to_bt(std::move(v)); } return res; } if (j.is_array()) { oxenc::bt_list res; for (auto& v : j) res.push_back(json_to_bt(std::move(v))); return res; } if (j.is_string()) { return std::move(j.get_ref()); } if (j.is_boolean()) return j.get() ? 1 : 0; if (j.is_number_unsigned()) return j.get(); if (j.is_number_integer()) return j.get(); throw std::domain_error{ "internal error: encountered some unhandled/invalid type in json-to-bt translation"}; } } // namespace llarp::rpc