C++ Weekly - Ep 319 - A JSON To C++ Converter

  Рет қаралды 19,168

C++ Weekly With Jason Turner

C++ Weekly With Jason Turner

Күн бұрын

☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
► ndctechtown.com/workshops/c-b...
Upcoming Workshop: Applied constexpr: The Power of Compile-Time Resources, C++ Under The Sea, October 10, 2024
► cppunderthesea.nl/workshops/
T-SHIRTS AVAILABLE!
► The best C++ T-Shirts anywhere! my-store-d16a2f.creator-sprin...
WANT MORE JASON?
► My Training Classes: emptycrate.com/training.html
► Follow me on twitter: / lefticus
SUPPORT THE CHANNEL
► Patreon: / lefticus
► Github Sponsors: github.com/sponsors/lefticus
► Paypal Donation: www.paypal.com/donate/?hosted...
GET INVOLVED
► Video Idea List: github.com/lefticus/cpp_weekl...
JASON'S BOOKS
► C++23 Best Practices
Leanpub Ebook: leanpub.com/cpp23_best_practi...
► C++ Best Practices
Amazon Paperback: amzn.to/3wpAU3Z
Leanpub Ebook: leanpub.com/cppbestpractices
JASON'S PUZZLE BOOKS
► Object Lifetime Puzzlers Book 1
Amazon Paperback: amzn.to/3g6Ervj
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Object Lifetime Puzzlers Book 2
Amazon Paperback: amzn.to/3whdUDU
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Object Lifetime Puzzlers Book 3
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Copy and Reference Puzzlers Book 1
Amazon Paperback: amzn.to/3g7ZVb9
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 2
Amazon Paperback: amzn.to/3X1LOIx
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 3
Leanpub Ebook: leanpub.com/copyandreferencep...
► OpCode Puzzlers Book 1
Amazon Paperback: amzn.to/3KCNJg6
Leanpub Ebook: leanpub.com/opcodepuzzlers_book1
RECOMMENDED BOOKS
► Bjarne Stroustrup's A Tour of C++ (now with C++20/23!): amzn.to/3X4Wypr
AWESOME PROJECTS
► The C++ Starter Project - Gets you started with Best Practices Quickly - github.com/cpp-best-practices...
► C++ Best Practices Forkable Coding Standards - github.com/cpp-best-practices...
O'Reilly VIDEOS
► Inheritance and Polymorphism in C++ - www.oreilly.com/library/view/...
► Learning C++ Best Practices - www.oreilly.com/library/view/...

Пікірлер: 61
@Joald
@Joald 2 жыл бұрын
Ah yes, C++ Weekly with JSON Turner
@Woockashek01
@Woockashek01 2 жыл бұрын
You should definetely rename it to JSON to CPP Turner
@Phroggster
@Phroggster 2 жыл бұрын
I don't know why there's all of this hate for clear enunciation and deliberate trains of thought. I watched (listened, mainly) while tending the grill on a loud windy day, so it was helpful. On to the meat of the video, I have no idea why I might potentially use this in the future, but I do know that I've wanted something similar to this in the past. So on behalf of future me, I thank you for the extra tool on my belt for use whenever the need arises.
@christopherhayden8442
@christopherhayden8442 2 жыл бұрын
Agreed. The solution is simple - bump up the speed if you want to go faster. I myself go at 1.5x, but it seems a little petty for someone to go out of their way to complain about something they have a fair amount of control over.
@titsbitchmcgee7502
@titsbitchmcgee7502 Жыл бұрын
I'm not gonna lie, I leave my playback speed untouched for every video I watch, instead of this one.
@LogicEu
@LogicEu 2 жыл бұрын
I think this tool has so much potential, great work!
@DamianReloaded
@DamianReloaded 2 жыл бұрын
Nice. I imagine you could also make the program convert the JSON to a static class/struct and have the compilation access the data by name instead of by key.
@AndrewCodeDev
@AndrewCodeDev 2 жыл бұрын
Great stuff, Jason!
@LenPopp
@LenPopp 2 жыл бұрын
But I thought that Jason converted to C++ a long time ago
@gtdcoder
@gtdcoder 2 жыл бұрын
Haha, good one 😂
@failsmichael2542
@failsmichael2542 2 жыл бұрын
He’s a Json Turner indeed.
@Dth091
@Dth091 2 жыл бұрын
When working with 'webpack' and other JS bundling tools, there are options for configuring transformers that pre-process imports (of any filetype theoretically, as long as you can write a transformer) into javascript code. I wonder if something like this combined with the #embed proposal could be useful? Of course, this would mean a hell of a lot more constexpr support in the compiler, and is really helped for the JS case since Node is both the target environment and the environment running the build tools.
@PedroOliveira-sl6nw
@PedroOliveira-sl6nw 2 жыл бұрын
I was thinking about config/**.ini files just as you mentioned configuration files. Nice
@beachedwhale
@beachedwhale 2 жыл бұрын
The raw strings shouldn't be necessary. JSON defines member names as valid JSON strings, so that is utf8 with only a few escapes that are needed(values
@Raspredval1337
@Raspredval1337 2 жыл бұрын
sorry, my question iscompletely unrelated to the video, but one day I needed to reemplement the std::optional, to somewhat cover the std::optional case. So I did a wrapper around std::aligned_storage, and everything seemed to be working fine, but then address sanitizer stated, that I had a bunch of "use after free" cases with that aligned storage. I started digging up the std library implementation of the optional and found out about the std::launder. I slapped that thing to my optional, and it magically fixed those uses after free. Can you clear that out for me, please? The cppref article about std::launder didn't help at all
@muluman88
@muluman88 2 жыл бұрын
Since it has the same API as nlohmann, could you simply use their test suite?
@cppweekly
@cppweekly 2 жыл бұрын
Great idea.
@alx9r
@alx9r 2 жыл бұрын
I’m puzzled by why I would want to specify configuration that is known at compile time in a different language. I suspect there is a good reason, but I haven’t yet found a case myself where I wasn’t better off factoring out a configuration source file in the language of the code it was configuring. What am I missing here?
@ltstaffel5323
@ltstaffel5323 2 жыл бұрын
It can reduce boilerplate and increase interoperability with other systems and languages. If the configuration is in JSON, it can more easily be generated or manipulated by other, automatic tools than source code. Usually you break out configuration like this when it becomes big enough that you don't enjoy doing it by hand.
@Omnifarious0
@Omnifarious0 2 жыл бұрын
A day early! I almost thought I'd gotten the day of the week wrong! Interesting tool though, thank you!
@metal571
@metal571 2 жыл бұрын
I think that's two episodes in a row now on a Sunday. Lol hopefully Jason is ok or maybe this is a permanent change
@JohnB5290
@JohnB5290 2 жыл бұрын
Why don't you simply escape backslashes and double quotes and include your string constants into ordinary double quotes? How do you handle unicode characters?
@robertfrysch7985
@robertfrysch7985 2 жыл бұрын
@jason: why the *_impl.hpp? Is there a reason against putting the implementation directly in the *.cpp file?
@robertfrysch7985
@robertfrysch7985 2 жыл бұрын
@ok I see! So for the compile time checks, you would need to include the *_impl.hpp, and for the runtime access (with zero overhead) you just need the *.hpp.
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
​@ok, thanks for the explanation!
@trcwm
@trcwm 2 жыл бұрын
Ha! very nice! 👍👍👍
@antoniocs8873
@antoniocs8873 2 жыл бұрын
So what is the use case for this? Am I correct in assuming it's just to incorporate a local JSON file into a C++ application by creating a class that has all it's data? So where would this be useful? Don't the majority of applications consume JSON at runtime? Possibly you have a web service that hits an API endpoint and gets load of data. That JSON has to be parsed at runtime. What you can do is maybe create a structure that would hold easily that JSON (somehow) but creating this data structure for something you have locally... not seeing how useful that is to the majority of people. If you have a massive JSON for configuration consider changing to SQLite or something. Maybe I'm missing something here....
@cppweekly
@cppweekly Жыл бұрын
It's called "cross training." Runners have to also weight lift if they want to become better runners. This is true of C++ as well. You sharpen your C++ by exposing yourself to other concepts outside of the language.
@jagansai007
@jagansai007 2 жыл бұрын
Compile time json converter is nice. But in the real world, the json files are read by the application during start up and they are converted to classes. Normally, servers are brought up much ahead of actual business time. In that case, what advantage does this bring?
@bloodgain
@bloodgain 2 жыл бұрын
I write simulators. High-fidelity simulators can take a _looooong_ time to start up due to heavy configuration, even for scenarios that might run in less time than they took to set up. I could easily see this being used to pre-compile scenario configurations as shared libraries and load them using dlopen. It would slow down scenario development, but scenarios are usually run far more often than they are changed and tested. It would also be easy enough to provide a "hot load" option that uses the JSON directly and sacrifices startup time for last-minute changes and scenario development.
@FedericoPekin
@FedericoPekin 11 ай бұрын
I can't compile it unfortunately
@cppweekly
@cppweekly 11 ай бұрын
Please open an issue on the project if you'd like me to look into it.
@0ptikGhost
@0ptikGhost 2 жыл бұрын
For those of you that don't understand why this might be useful, you don't work with a resource constrained system that would clearly benefit from this. This video is not for you unless you want to play around with the techniques used or learn how to use them better. Jason mentions at least two examples where something like this could be useful.
@DanielHsHu
@DanielHsHu Жыл бұрын
Well I can make a configiguration as an .h files with a set of #define instead of this Json parser and it will be much faster to compile.
@gtdcoder
@gtdcoder 2 жыл бұрын
What’s with all the speed comments? He’s trying to be clear and articulate.
@DrGreenGiant
@DrGreenGiant 2 жыл бұрын
I don't understand those comments either. Seems fine to me
@oracleoftroy
@oracleoftroy 2 жыл бұрын
It's funny that they are appearing now. He's always used this pace in his videos, and I don't ever recall comments about it. I like to set the speed to 1.5, but it never occurred to me to complain about it. His style works great and youtube features can easily adjust the pace to each listener's preferences.
@alexandrebustico9691
@alexandrebustico9691 2 жыл бұрын
As a foreign viewer, I particularly appreciate how Jason speaks, I can understand what he says without reading subtitles. Don't change anything Jason !
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
Why do you use the ugly include guard technique from 1978 instead of #pragma once?
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
@ok , it is de facto standard, I don't know a single compiler that doesn't support it (including the embedded ones).
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
​@ok, it does because what you suggested could be an issue is actually not.
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
​@ok, those compilers will also not support C++17/20/23, but for some reason you didn't say this JSON library is at fault by using these modern standards. Supporting shit compilers requires writing shit code, which, luckily, is not the scope of this channel.
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
​@ok, I challenge you to find an example of a compiler that supports C++17 and doesn't support pragma once. I very seriously doubt one exists, and I don't understand why you're being so dense about it.
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
​@ok, and more importantly, you call it a minor stylistic decision, but I call it proliferation and perpetuation of bad coding practice. Obviously, you've never hunted down a bug caused by clashing include guards, so it is you who has little experience.
@DS127
@DS127 2 жыл бұрын
I'm one of those people who set most vids on KZfaq at 2x speed. You aren't an especially slow speaker.
@hanabimock5193
@hanabimock5193 2 жыл бұрын
A noob here, why is this necessary? Looks like a hassle.
@ohwow2074
@ohwow2074 2 жыл бұрын
Why do you slow down your videos? Feels like you intentionally set it to 0.5X
@VioletGiraffe
@VioletGiraffe 2 жыл бұрын
nlohmann JSON library is the worst one I've tried. It is incredibly, ridiculously slow. Although the API is nice, much better than RapidJSON.
@peterbassett2179
@peterbassett2179 2 жыл бұрын
1.5x speed makes you sound like a human. 2x at least to get through this. Stop slowing down your videos.
@iordanslavov907
@iordanslavov907 2 жыл бұрын
Set speed to 1.25. Thank me later
@TheMR-777
@TheMR-777 2 жыл бұрын
I watch at 1.75 :), always
@metal571
@metal571 2 жыл бұрын
2x all of this series
@peterfordham3562
@peterfordham3562 2 жыл бұрын
1.5x for me, when I watch now at normal speed it sounds to me like he's had a stroke.
@miguellorenzo3726
@miguellorenzo3726 2 жыл бұрын
Lol
@italoaugustooliveira9664
@italoaugustooliveira9664 2 жыл бұрын
This looks very ugly tbh.
@trcwm
@trcwm 2 жыл бұрын
That's what she said.
C++ Weekly - Ep 320 - Using `inline namespace` To Save Your ABI
7:40
C++ Weekly With Jason Turner
Рет қаралды 13 М.
C++ Weekly - Ep 332 - C++ Lambda vs std::function vs Function Pointer
16:30
C++ Weekly With Jason Turner
Рет қаралды 32 М.
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 9 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 476 М.
Cool Items! New Gadgets, Smart Appliances 🌟 By 123 GO! House
00:18
123 GO! HOUSE
Рет қаралды 17 МЛН
I wrote my own JSON parser. Also, JSON is a terrible standard.
28:54
C++ Weekly - Ep 359 - std::array's Implementation Secret (That You Can't Use!)
11:21
C++ Weekly With Jason Turner
Рет қаралды 27 М.
C++ Weekly - Ep 421 - You're Using optional, variant, pair, tuple, any, and expected Wrong!
10:34
C++ Weekly - Ep 334 - How to Put a Lambda in a Container
11:51
C++ Weekly With Jason Turner
Рет қаралды 15 М.
C++ Weekly - Ep 313 - The `constexpr` Problem That Took Me 5 Years To Fix!
26:19
C++ Weekly With Jason Turner
Рет қаралды 23 М.
CppCon 2015: Huu Nguyen "C++ Requests - Curl for People"
9:39
C++ Weekly - Ep 374 - C++23's out_ptr and inout_ptr
13:38
C++ Weekly With Jason Turner
Рет қаралды 17 М.
C++ Weekly - Ep 322 - Top 4 Places To Never Use `const`
18:53
C++ Weekly With Jason Turner
Рет қаралды 35 М.
low battery 🪫
0:10
dednahype
Рет қаралды 573 М.
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 420 М.
Ноутбук за 20\40\60 тысяч рублей
42:36
Ремонтяш
Рет қаралды 379 М.
ВАЖНО! Не проверяйте на своем iPhone после установки на экран!
0:19
ГЛАЗУРЬ СТЕКЛО для iPhone и аксессуары OTU
Рет қаралды 6 МЛН
Сколько реально стоит ПК Величайшего?
0:37
Самые крутые школьные гаджеты
0:49