TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JSON for Classic C++

117 pointsby davikr6 months ago

14 comments

conradev6 months ago
I remember searching for a JSON library with minimal dependencies a while ago, and came across this:<p><a href="https:&#x2F;&#x2F;rawgit.com&#x2F;miloyip&#x2F;nativejson-benchmark&#x2F;master&#x2F;sample&#x2F;conformance.html" rel="nofollow">https:&#x2F;&#x2F;rawgit.com&#x2F;miloyip&#x2F;nativejson-benchmark&#x2F;master&#x2F;sampl...</a><p>The variance in feature set, design and performance is huge across all of them. I ultimately landed on libjson, written in C: <a href="https:&#x2F;&#x2F;github.com&#x2F;vincenthz&#x2F;libjson">https:&#x2F;&#x2F;github.com&#x2F;vincenthz&#x2F;libjson</a><p>It does a lot for you, but it notably does not build a tree for you and does not try to interpret numbers, which I found perfect for adding to languages with C FFI that have their own collection and number types. It’s also great for partial parsing if you need to do any sort of streaming.<p>It looks like this one can’t currently do partial parsing, but it looks great if C++ maps&#x2F;vectors are your target.
评论 #42133522 未加载
评论 #42133379 未加载
评论 #42133313 未加载
darknavi6 months ago
Compile time is largely a &quot;developer problem&quot;, but so is the usability of a library. nlohmann&#x2F;json&#x27;s main perk that it is selling is that it&#x27;s interface is usable. Whether or not a developer values usability at typing time vs compile time is an interesting thing to ponder for sure.
评论 #42133465 未加载
评论 #42133670 未加载
评论 #42134822 未加载
ur-whale6 months ago
Code in jart&#x27;s version is refreshingly clean and easy to read compared the nlohmann&#x27;s version.<p>As an aside, I wonder: what are the ThomPike* set of macros actually doing in jart&#x27;s implem ?<p>Also, a speed comparison of this vs the other one would be very welcome: conformance and simplicity are certainly important criteria when picking a JSON parser, but speed is rather crucial.
评论 #42133444 未加载
henshao6 months ago
Really interesting that nlohmann isn&#x27;t fully compliant. What cases are these?<p>It seems to me though that if you&#x27;re encountering the edges of json where nlohmann or simple parsing doesn&#x27;t work properly, a binary format might be better. And if you&#x27;re trying to serialize so much data that speed actually becomes an issue, then again, binary format might be what you really want.<p>The killer feature of nlohmann are the the NLOHMANN_DEFINE_TYPE_INTRUSIVE or NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macros that handle all of the ??? -&gt; json -&gt; ??? steps for you. That alone make it my default go to unless the above reasons force me to go another direction.
评论 #42159014 未加载
leni5366 months ago
On the other end of the spectrum there is [1]. It&#x27;s both performance and usability oriented, although compile times are probably higher.<p>Nlohmann is the slowest out of the popular libraries, AFAIK, and not particularly more usable than rapidjson, in my experience. So &quot;better than nlohmann&quot; is not very novel.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;beached&#x2F;daw_json_link">https:&#x2F;&#x2F;github.com&#x2F;beached&#x2F;daw_json_link</a>
psyclobe6 months ago
The moment nlohmann&#x27;s library came out, I switched to it and I never looked back.<p>I loved the interface and its exactly how I would&#x27;ve designed a json library with modern c++.<p>Just maybe turn off the implicit conversion option, that can get a bit messy ;)
zeroq6 months ago
&quot;This project is a reaction agains...&quot; is such a punk move I can&#x27;t do anything but appreciate.
cod1r6 months ago
jart is such a good programmer. a lot of people already know this but i just have to give props where it&#x27;s due.
评论 #42133496 未加载
makz6 months ago
What does “Classic C++” mean?
评论 #42133262 未加载
评论 #42133318 未加载
评论 #42133140 未加载
nurettin6 months ago
This is a fine library, but I use nlohmann extensively and haven&#x27;t experienced any considerable compilation slowdown once I added it to the project.<p>Overloading from_json to modularize parsing is really useful, I think that should be a part of every templated C++ json parser library.<p>That said, I have seen these ThomPike* macros in cosmopolitan.h before, I wonder what the origin is.
评论 #42141567 未加载
0x1ceb00da6 months ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;jart&#x2F;json.cpp&#x2F;blob&#x2F;4f0a02dab1af7d81888cf5887c20cf5d71415efa&#x2F;json.h#L45">https:&#x2F;&#x2F;github.com&#x2F;jart&#x2F;json.cpp&#x2F;blob&#x2F;4f0a02dab1af7d81888cf5...</a><p>The response doesn&#x27;t tell you the location of the problem in the input.
评论 #42133400 未加载
tsurnyc6 months ago
What are the performance numbers? nlohmann&#x2F;json is no speed demon.
评论 #42133407 未加载
UncleOxidant6 months ago
Sounds like there&#x27;s a backlash to modern C++.
madduci6 months ago
Interesting approach, but without providing a conan&#x2F;vcpkg in (the end of) 2024, makes only friction.<p>We are not living in 90s anymore..
评论 #42133662 未加载