Questions tagged [boost-propertytree]

The Boost PropertyTree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. It serializes and emulates XML, JSON and INI file structures.

The Boost PropertyTree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. It serializes and emulates XML, JSON and INI file structures.

Note: Boost.PropertyTree is not a generic XML parser. It is not intended to be used as a fast-and-dirty way to load arbitrary XML files into memory. It's XML serialization capabilities are for serialization. It is intended to read the XML that it has written.

Please stop using Boost.PropertyTree as a generic XML parser.

287 questions
71
votes
3 answers

Serializing and deserializing JSON with Boost

I'm newbie to C++. What's the easiest way to serialize and deserialize data of type std::Map using boost. I've found some examples with using PropertyTree but they are obscure for me.
user1049280
  • 4,946
  • 8
  • 31
  • 51
70
votes
6 answers

Creating JSON arrays in Boost using Property Trees

I'm trying to create a JSON array using boost property trees. The documentation says: "JSON arrays are mapped to nodes. Each element is a child node with an empty name." So I'd like to create a property tree with empty names, then call…
Chris Stucchio
  • 851
  • 1
  • 8
  • 4
66
votes
7 answers

Why does Boost property tree write_json save everything as string? Is it possible to change that?

I'm trying to serialize using boost property tree write_json, it saves everything as strings, it's not that data are wrong, but I need to cast them explicitly every time and I want to use them somewhere else. (like in python or other C++ json (non…
pprzemek
  • 2,325
  • 2
  • 23
  • 24
41
votes
4 answers

Boost PropertyTree: check if child exists

I'm trying to write an XML parser, parsing the XML file to a boost::property_tree and came upon this problem. How can I check (quickly) if a child of a certain property exists? Obviously I could iterate over all children using BOOST_FOREACH -…
paul23
  • 7,226
  • 9
  • 44
  • 108
33
votes
3 answers

boost::property_tree XML pretty printing

I'm using boost::property_tree to read and write XML configuration files in my application. But when I write the file the output looks kind of ugly with lots of empty lines in the file. The problem is that it's supposed to be edited by humans too so…
foke
  • 1,299
  • 2
  • 11
  • 19
30
votes
3 answers

Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees?

First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on this official example of empty ptree trick. There you can find next line: const ptree &settings =…
Rella
  • 59,216
  • 102
  • 341
  • 614
28
votes
2 answers

Using boost property tree to read int array

I have some JSON with a handful of integer array variables, like so: {"a": [8, 6, 2], "b": [2, 2, 1]} I would like to use boost property_tree, for instance: std::stringstream ss; boost::property_tree::ptree pt; ss << "{\"a\": [8, 6, 2], \"b\": [2,…
Larry
  • 319
  • 1
  • 4
  • 10
26
votes
5 answers

How to iterate a boost property tree?

I am know approaching to boost property tree and saw that it is a good feature of boost libs for c++ programming. Well, I have one doubt? how to iterate a property tree using iterators or similar? In reference there is just an example of browsing…
Andry
  • 14,281
  • 23
  • 124
  • 216
22
votes
2 answers

How are attributes parsed in Boost.PropertyTree?

Say I have this XML format: dostuff(); How do I read the attributes using Boost.PropertyTree?
the_drow
  • 17,134
  • 23
  • 116
  • 185
19
votes
3 answers

How to feed Boost.PropertyTree with a string, not a file?

Boost has a tutorial on how to load XML from a file. How do I feed it with a string that I either create in code or receive from a user (e.g. with cin)?
Rella
  • 59,216
  • 102
  • 341
  • 614
19
votes
4 answers

framework/library for property-tree-like data structure with generic get/set-implementation?

I'm looking for a data structure which behaves similar to boost::property_tree but (optionally) leaves the get/set implementation for each value item to the developer. You should be able to do something like this: std::function f_foo =…
frans
  • 6,905
  • 8
  • 40
  • 95
18
votes
3 answers

Parsing XML Attributes with Boost

I would like to share with you an issue I'm having while trying to process some attributes from XML elements in C++ with Boost libraries (version 1.52.0). Given the following code: #define ATTR_SET "." #define XML_PATH1…
grover999
  • 235
  • 1
  • 2
  • 6
17
votes
2 answers

How do I merge/update a boost::property_tree::ptree?

I have read through the documentation for boost::property_tree and have not found a way to update or merge a ptree with another ptree. How do I do this? Given the code below, how would the update_ptree function look like? #include…
mantler
  • 819
  • 7
  • 19
15
votes
3 answers

Boost Property_Tree iterators, how to handle them?

I am sorry, I asked a question about the same topic before, but my problem concerns another aspect of the one described there (How to iterate a boost...). Take a look at the following code: #include #include #include…
Andry
  • 14,281
  • 23
  • 124
  • 216
15
votes
1 answer

C++: How to create an array using boost::property_tree?

I don't see a way to create an array using boost::property tree. The following code ... #include #include #include int main() { try { …
Jan Deinhard
  • 17,925
  • 24
  • 75
  • 131
1
2 3
19 20