MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / AccessJsonArrayIndex

Function AccessJsonArrayIndex

lib/utils/json-helpers.cpp:82–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82std::optional<std::string> AccessJsonArrayIndex(const std::string &jsonStr,
83 const int index)
84{
85 try {
86 nlohmann::json json = nlohmann::json::parse(jsonStr);
87 if (!json.is_array() || index >= (int)json.size() ||
88 index < 0) {
89 return {};
90 }
91 auto result = json.at(index);
92 if (result.is_string()) {
93 return result.get<std::string>();
94 }
95 return result.dump();
96 } catch (const nlohmann::json::exception &) {
97 return {};
98 }
99 return {};
100}
101
102std::optional<std::string>
103ExtractSingleJsonArrayElement(const std::string &jsonStr)

Callers 2

PerformActionMethod · 0.85
test-json.cppFile · 0.85

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected