Search code examples
c++jsonboostboost-propertytree

Are comments allowed in a JSON file for boost read_json?


This is a homotopy of the json file I always used to read through boost::property_tree::json_parser::read_json

And it was always working.

/**********************************************/
/*                 the title                  */
/**********************************************/



{
    "garden": {
        "side1": {
            "treeA1": "apple",
            "treeA2": "orange",
            "treeA3": "banana",
        },
        "side2": {
            "treeB1": "orange",
            "treeB2": "palm",
            "treeB3": "cherry",
        }
    },
    "house": ""
}

I upgraded my boost version from 1.58.0 to 1.65.0 and now I receive an exception because of the comments. When I remove the comments, everything is fine.

Am I making a mistake somewhere or is it a bug in the new version of boost?


Solution

  • Comments are not JSON.

    The old parser did have them, but didn't properly support unicode.

    Here's the message in the release notes for Boost 1.59.0:

    Property Tree:

    • A new JSON parser with full Unicode support.
    • Breaking change: The new parser does not support comments or string concatenation in JSON files. These features were non-standard extensions of the old parser but their removal could break code which was relying on them.