| 80 | } |
| 81 | |
| 82 | std::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 | |
| 102 | std::optional<std::string> |
| 103 | ExtractSingleJsonArrayElement(const std::string &jsonStr) |
no test coverage detected