Boost PropertyTree: read_json() followed by write_xml produces invalid XML
Hi all,
I was quite surprised and disappointed to find out that I was unable
to convert a simple JSON file into XML, using the Boost PropertyTree.
As input I used the example JSON file from the documentation (see
example.json below).
I wrote a small program (see example.cc below) that reads in this JSON
file, writes it to disk as XML file, and finally tries to read back
this XML file. This last operation fails with an exception (see output
below); the XML file that is produced (see example.xml below) is
invalid, because it contains empty tags (<>).
Am I doing something wrong?
Best regards,
Marcel Loose.
$ cat example.json
{
"menu":
{
"foo": true,
"bar": "true",
"value": 102.3E+06,
"popup":
[
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"}
]
}
}
$ cat example.cc
#include
Boost.PropertyTree is not a JSON library nor a XML library. It's a property tree library that happen to have functions to create JSON-compatible or XML compatible output or read from one. See: - http://lists.boost.org/boost-users/2013/02/77471.php - https://groups.google.com/forum/#!topic/boostusers/IjASBJvwhVY There are apparently work in progress for an Boost JSON library but I don't have the details right now. For the time being, maybe you can use JSonCPP or JSon Spirit libraries.
On Sun, Apr 27, 2014 at 03:43:43PM +0200, Klaim - Joël Lamotte wrote:
Boost.PropertyTree is not a JSON library nor a XML library. It's a property tree library that happen to have functions to create JSON-compatible or XML compatible output or read from one.
The example JSON file he lists is verbatim from the documentation, and the problem seems to be that the chain of operations read PT conformant JSON write PT XML read PT XML into the same ptree object fails. Surely PT's XML writer should emit XML that PT's XML reader groks? -- Lars Viklund | zao@acc.umu.se
participants (3)
-
Klaim - Joël Lamotte
-
Lars Viklund
-
Marcel Loose