Bug 782 - Ledger produces xml/json with only one or two entries.
Summary: Ledger produces xml/json with only one or two entries.
Alias: None
Product: Ledger
Classification: Unclassified
Component: data (show other bugs)
Version: 3.0.0
Hardware: All All
: P1 normal
Assignee: John Wiegley
: 909 (view as bug list)
Depends on:
Reported: 2012-07-15 16:54 UTC by Jesse Rosenthal
Modified: 2016-01-22 18:15 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Rosenthal 2012-07-15 16:54:55 UTC
There seems to be a problem with the PropertyTree that produces the xml/json output. Though the format of this output isn't documented, the below seem clearly faulty: there are only a couple of accounts listed. In addition, I don't see the logic of the nestings -- why is "Mortgage:Principle" a child of "Tithe"?

(Note that, in order to avoid pasting in too much output, I've grepped to get only the "fullname" of the accounts. I'd be happy to resubmit with the full output).

$ ledger --version  
Ledger 3.0.0-20120518, the command-line accounting tool

Copyright (c) 2003-2012, John Wiegley.  All rights reserved.

This program is made available under the terms of the BSD Public License.
See LICENSE file included with the distribution for details and disclaimer.

$ ledger -f test/input/drewr.dat xml|tidy -xml -i -q|grep fullname
      <fullname />

$ ledger -f test/input/drewr.dat json|grep fullname               
                "fullname": "",
                    "fullname": "Liabilities",
                        "fullname": "Liabilities:Tithe",
                            "fullname": "Liabilities:Mortgage:Principal",
Comment 9 John Wiegley 2013-05-23 04:56:40 UTC
This was fixed by Johann a little while back.
Comment 8 John Wiegley 2013-05-23 03:35:17 UTC
Is this still an issue, Jesse?  I just ran the xml report on drewr3.dat, and 
saw lots of XML output...
Comment 7 John Wiegley 2013-05-20 03:02:22 UTC
Pinging Johann.
Comment 6 John Wiegley 2013-05-19 03:49:27 UTC
I say we drop json support altogether, then.  Johann, do you want to make that 
Comment 5 Johann Klähn 2013-03-08 16:19:55 UTC
*** Bug 909 has been marked as a duplicate of this bug. ***
Comment 4 Johann Klähn 2013-01-16 15:43:55 UTC
Hm. This will take some time to get right for both JSON and XML as they have different PropertyTree strutures. Whereas you would set attributes nested under '<xmlattr>' for XML output, those attributes would have to be set on the object directly for valid JSON:

commodity {
  flags "P"


commodity {
  <xmlattr> {
    flags "P"

A second and even more important difference is how you specify a list of items:

XML: ( using ptree& child(pt.add("commodity","")) )
commodities {
  commodity {
    symbol "$"
  commodity {
    symbol "€"

JSON: ( using pt.push_back(std::make_pair("", child)) )
commodities {
  "" {
    symbol "$"
  "" {
    symbol "€"

Only this leads to valid JSON:
{"commodities": [{"symbol": "$",…},{"symbol": "€",…},…] }

John, what's your opinion on format specific code in put_*? Or drop JSON support alltogether? (Could be redone using python bindings.) Maybe this whole code would benefit from a restructure but I don't have a clear idea yet.
Comment 3 Johann Klähn 2013-01-15 17:03:10 UTC
I think this may boil down to using pt.add() instead of pt.put() in some places. I will work on a patch tomorrow.

  self_type & put(const path_type & path, const Type & value);
… If the node doesn't exist, it is created, including all its missing parents. …

  self_type & add(const path_type & path, const Type & value);
… If the node already exists, add a sibling with the same key. …
Comment 2 Jesse Rosenthal 2012-10-03 11:52:13 UTC
Upgrading this to P1, as per John's recent request on the mailing list.

These subcommands (json, xml) would be of great importance to many wanting to integrate ledger into web-apps and multi-language toolchains. If they fail, as they do now, it would be quite confusing. Either they should be fixed, or they should be removed and users should be directed to parse their own custom-formatted output.
Comment 1 Jesse Rosenthal 2012-07-15 16:55:59 UTC
Note as well that I used drewr.dat to have a common reference, but I've encountered this problem on every file I've tried it with.