Boost logo

Boost Users :

Subject: [Boost-users] [property_tree] Writing comments in JSON format
From: Ruediger Berlich (ruediger.berlich_at_[hidden])
Date: 2011-09-06 04:20:11

Hi there,

by trying it out with a modified debug_settings example, I can see that
property_tree accepts Javascript ("//") comments inside of the JSON files it

I want to find out whether it makes sense to use JSON as an alternative to
boost.program_options for configuration files. The idea would be to use a
JavaScript-based GUI to modify or create the configuration files in a
comfortable way and to use the same files as input for my C++-based

As my configuration files are auto-generated by my objects and not everybody
loves GUIs, I need to be able to add comments to a property_tree object, so
that they are emitted during a "write_json" call.

The easiest way to add comments to the config files would be to just add a
"comment" data member. This would indeed be very useful for the JavaScript
usecase, as comments can be integrated into the GUI / Browser, and would
still give guidance to those wanting to modify the JSON files with a
standard editor. However, this does not help me to write things like a
header, or to add information targeted only at those who modify the files by
hand. For these I still need to be able to generate "//"-style comments.

From the documentation I could not find out whether this can be done in a
standard and portable way. Any pointer would be very welcome!

Thanks and Best Regard,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at