Boost C++ Libraries: Ticket #9495: property_tree json_read should accept iterators instead of just streams https://svn.boost.org/trac10/ticket/9495 <p> For a project I am using boost::property_tree abundantly. The trees need to be transfered across all kinds of interfaces and I have ran the limited function call several times. </p> <p> It requires a istream to read from. To make matters worse, as soon as it enters the function, a complete copy is made to a vector. And that happens when I already had to make a copy because the read_json method expects to consume all input data, which rarely happens for me. I know the exact beginning and ending position in the stream, but there is no way to specify this. </p> <p> The following function signature would be prefered: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iterator</span><span class="p">,</span> <span class="k">class</span> <span class="nc">Ptree</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">read_json_internal</span><span class="p">(</span><span class="n">Iterator</span> <span class="n">begin</span><span class="p">,</span> <span class="n">Iterator</span> <span class="n">end</span><span class="p">,</span> <span class="n">Ptree</span> <span class="o">&amp;</span><span class="n">pt</span><span class="p">,</span> <span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="o">&amp;</span><span class="n">filename</span><span class="p">)</span> </pre></div></div><p> This signature could still be used by the existing read_json_internal, which first converts this to a vector and then passed the vector iterators begin and and to this function, to avoid code duplication. </p> <p> Of course, the proper front-end in json_parser.hpp needs to be added to. </p> <p> The benefit is that this method can operate directly on my input sequence where I can specify exactly where the JSON states and where the JSON ends, avoiding all copies completely. </p> <p> I will attach a patch based on SVN Trunk that will accomplish this. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9495 Trac 1.4.3 Egbert van der Wal <ewal@…> Sun, 15 Dec 2013 11:57:50 GMT attachment set https://svn.boost.org/trac10/ticket/9495 https://svn.boost.org/trac10/ticket/9495 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_property_tree.patch</span> </li> </ul> <p> Patch to add a iterator accepting variant of boost::property_tree::read_json </p> Ticket anonymous Mon, 10 Feb 2014 13:28:58 GMT <link>https://svn.boost.org/trac10/ticket/9495#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9495#comment:1</guid> <description> <p> Any idea when/if this will be merged for a new Boost release? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Tue, 07 Jul 2015 14:05:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9495#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9495#comment:2</guid> <description> <p> I rewrote the JSON parser. The new parser is completely iterator-based. I will soon define a front-end to make it possible to parse from iterators without reaching into the detail namespace. </p> </description> <category>Ticket</category> </item> </channel> </rss>