marzer / tomlplusplus

Header-only TOML config file parser and serializer for C++17.
https://marzer.github.io/tomlplusplus/
MIT License
1.58k stars 152 forks source link

how to get json string, directly instead of having to serializing into a stream first? #137

Closed pkbehera closed 2 years ago

pkbehera commented 2 years ago
  auto pr = toml::parse_file(toml_file);
  if (pr) {
    stringstream ss;
    ss << toml::json_formatter(pr.table());
    auto json_str = ss.str(); 
  }

The above does work, but an API like to_string() would be much more useful. Does it exist?

marzer commented 2 years ago

Doesn't currently exist, but could be added.

would be much more useful

It would be more useful for you specifically.

pkbehera commented 2 years ago

It would be more useful for you specifically.

sure and faster!

marzer commented 2 years ago

How would it be any faster? The formatters are all stream-based, so any implementation of this would just do something like what you've done above, hidden in a function. It would be exactly the same speed.

Unless you're implying I should re-write the formatters, in which case, no.

pkbehera commented 2 years ago

Doesn't currently exist, but could be added.

and still closed?

marzer commented 2 years ago

Yes, I decided this feature would be far too niche to bother putting in the library itself. If you want a function to convert TOML to a JSON string, you can make a helper function in your own codebase.

marzer commented 2 years ago

@pkbehera look mate you can take your thumbs-down emoji and the rest of your attitude and fuck off.

I'm already giving you a way to convert TOML into JSON, which is more than you'll find in any of the other C++ TOML libraries.

Don't give me fucking shitty attitude because you have to do the last 1% of the work, you poor baby.