반응형
참고: JsonCpp로 적용되어 있는 기존의 Json library를 Nlohman/Json으로 바꾸자를 제안이 있어서 조사하였으며, 조사의 결과는
[C++] C++ Json 라이브러리 성능비교(벤치마크): JsonCpp, Nlohmann/json 에 정리해놓았습니다.
이 문서는 조사의 결과, 성능과 편의성 측면에서 우수한 Nlohman/Json으로 교체하기 위한 과정을 기록한 문서이니 참고 부탁드립니다.
JsonCpp to Nlohmann/json
Generate json
JsonCpp
Json::Value json;
Nlohmann/json
nlohmann::json json;
nlohmann::ordered_json ordered_json; // 넣는 순서대로 프린트되는 json 형태
- Nlohmann/json에 대한 자세한 내용은 [OpenSource 사용하기] nlohmann/json: c++ json library 를 참고하시기 바랍니다.
Export json
JsonCpp
std::string content = json["source"].asString()
uint64_t content = json["source"].asUInt64()
Nlohmann/json
std::string content = json["source"].get<std::string>()
uint64_t content = json["source"].get<uint64_t>()
Null Check
JsonCpp
if (json["source"] == Json::nullValue)
Nlohmann/json
if (json["source"].is_null())
if (json["source"] == nullptr)
Field/Colume Check
JsonCpp
if (json.isObject() && json.isMember("source"))
Nlohmann/json
if (json["key"].find("source") != json["key"].end())
if (json["key"].contains("source"))
json to std::string
JsonCpp
// stringstream
Json::StreamWriterBuilder wbuilder;
wbuilder["commentStyle"] = "None";
wbuilder["indentation"] = "";
std::unique_ptr<Json::StreamWriter> jsonStreamWriter;
jsonStreamWriter.reset(wbuilder.newStreamWriter());
std::string content = Json::writeString(wbuilder, json);
std::string content = json.toStyledString()
Nlohmann/json
std::string content = json.dump()
About nlohmann::json
- Nlohmann/json에 대한 자세한 내용은 [OpenSource 사용하기] nlohmann/json: c++ json library 를 참고하시기 바랍니다.
참고
- [Github] nlohmann json: https://github.com/nlohmann/json
- [JsonCpp] JsonCpp basic tutorial: https://jsoncpp.docsforge.com/
- [JsonCpp] JsonCpp doxygen: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
- [JsonCpp] StreamWriterBuilder: https://jsoncpp.docsforge.com/master/api/Json/StreamWriterBuilder/
- LibHunt: Library Benchmark: https://www.libhunt.com/compare-json-vs-jsoncpp?ref=compare
반응형
'Study: Software(SW) > SW: Opensource' 카테고리의 다른 글
[Opensource] C++ 라이브러리 추천! : cppreference.com (0) | 2022.09.11 |
---|---|
[OpenSource 사용하기] fmt: C++ formatting library (feat. python styled print) (2) | 2022.08.18 |
[OpenSource 사용하기] googleMock(gMock): C++ Mocking Library for googletest (0) | 2022.07.16 |
[OpenSource 사용하기] nlohmann/json: c++ json library (feat. Modern C++) (0) | 2022.07.05 |
[OpenSource 사용하기/뜯어보기] OpenSource 사용하기/뜯어보기 개요 및 목록 (0) | 2022.06.29 |