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.

354 questions
3
votes
1 answer

boost::property_tree::ptree accessing array's first complex element

My JSON is this: { "apps":[ { "id":"x", "val":"y", } ] } I can get id's value "x" by looping, and exiting when it.first is id: for (const ptree::value_type &app : root.get_child("apps")) { for…
Grzegorz
  • 3,207
  • 3
  • 20
  • 43
3
votes
1 answer

Checking if a path exists in a boost property tree

How do I check if a path exists in a property tree? Example: boost::property_tree::ptree tree; // if path doesn't exist, put value if (/*...*/) { tree.put("my.path.to.thing", true); }
Nybbit
  • 293
  • 2
  • 10
3
votes
2 answers

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 …
ar2015
  • 5,558
  • 8
  • 53
  • 110
3
votes
1 answer

Getting boost property_tree parent node

I am using boost property_tree in my program. I've set up the tree for using custom path type. What I'm looking for is getting a specific node's parent node id. Here is an example: MetaStorageTree tree; typedef…
Egor Chubarov
  • 208
  • 1
  • 13
3
votes
1 answer

C++ boost ptree rename key

In a boost property tree, I would like to rename a key such as a.b.c2 to a.b.c3. One method is to remove the node and put its copy with another name. The problem is that the node is placed at the end of its other siblings. I prefer to keep the…
ar2015
  • 5,558
  • 8
  • 53
  • 110
3
votes
1 answer

Boost::property_tree: Using std::vector<> in XML parser to store multiple values in one key

My question is related to this question: Boost property_tree: multiple values per key and to a question following that question: Boost property_tree: multiple values per key, on a template class. I am trying to parse an XML file in which multiple…
Sjonnie
  • 115
  • 1
  • 6
3
votes
2 answers

Auto-interpreting a c-style string as a std::string via Boost's Property tree's .get function

I use boosts property tree, included via #include "boost\property_tree\ptree.hpp" And... I'd like to create a simple function which substitutes a value in case none is found via a fairly straight-forward template function: template
Gazoo
  • 215
  • 4
  • 14
3
votes
1 answer

How to rename node/element in boost property tree?

For example I have boost property tree of following structure (created by reading stream with xml or in different way): How to rename in existing tree element B to new element with new key: N. So invoking…
Vlad
  • 1,977
  • 19
  • 44
3
votes
1 answer

boost ptree modify an array of values on the fly

I started using the ptree and the json parser from boost to save some quick information. The problem is that I only need to save some URI, so I don't care about a key. Now I want to find a certain value and remove it. How can I do this { …
user3842408
  • 89
  • 1
  • 10
3
votes
2 answers

boost::ptree find? or how to access deep arrays? C++

I have been trying for too much time now, to access a json_reader ptree from the boost library. I have a json file that is capsulated really often: (pseudo-json:) "Foo": { "nameofFoo:"foofoo" "Bar": [{ "BarFoo": { BarFooDeep: { …
Druide
  • 48
  • 1
  • 6
3
votes
2 answers

Is there a convenient way to erase a node from a property tree, preserving its child nodes?

I want to delete a node from a boost property tree, but I want to preserve its children and connect them to the parent of the deleted node (i.e. to their grandparent node). Is there an elegant way to achieve this?
Marste
  • 627
  • 7
  • 22
3
votes
1 answer

c++ boost library - writing to ini file without overwriting?

im trying to write an ini file using boost library's ini parser and property tree. The file is written in stages - i mean every function writes a portion of it. At the end im left with only the last output instead of having everything written…
vito
  • 323
  • 1
  • 10
3
votes
1 answer

How to use boost::property_tree to parse JSON with array root

How can I get data from JSON with array as root node by using Boost.PropertyTree? [ { "ID": "cc7c3e83-9b94-4fb2-aaa3-9da458c976f7", "Type": "VM" } ]
likern
  • 3,744
  • 5
  • 36
  • 47
3
votes
3 answers

Reading INI file using Boost Property Tree when value section does not exist

I'm using Boost.PropertyTree to read INI file: read_ini( "myIni.ini", pt ); string s=pt.get("Section1.value1"); If section doesn't contain value1 record then Boost raises exception. How to read INI file in an elegant way and give a…
vico
  • 17,051
  • 45
  • 159
  • 315
3
votes
1 answer

boost::property_tree::info_parser breaks on spaces in value

I am facing an issue where I have a configuration file and I parse it with boost::property_tree:info_parser. I use this code to do the work: struct _Config { std::string info[2]; boost::property_tree::ptree pt; _Config() { …
Gizmo
  • 1,990
  • 1
  • 24
  • 50