The --output-format option accepts txt and csv so far. For better parsing of the output, json would be awesome !
Currently I use the hledger-api for json-formatted data, which is fantastic but is limited to only a few commands. I would also appreciate a feature like this.
Both would be good to improve, patches welcome!
Copied from #1069:
We have ToJSON instances in hledger-web/Hledger/Web/JSON.hs, which perhaps should move into hledger-lib; then it shouldn't be too hard to add this, handling any tricky cases like mutual references as hledger-web does. See also hledger-web/Hledger/Web/Handler/MiscR.hs.
There seems to be an experimental json output but it's not actually outputting JSON but some sort of DSL, is this something that broke or was it never implemented?
@entropitor could you show a repro of what you're talking about ?
https://hledger.org/hledger-web.html#json-api was updated yesterday, describing the JSON served by hledger-web. If someone wants to add this output format to some hledger commands, starting with print, that would be great.
When I have the following test.ledger file
2020/05/23 * My favorite resto
expenses:food € 26.8
assets:cash € -26.8
And run:
hledger -f test.ledger bal -O json
I get:
Array [Array [Array [String "assets:cash",String "assets:cash",Number 0.0,Array [Object (fromList [("aprice",Null),("acommodity",String "\8364"),("aquantity",Object (fromList [("floatingPoint",Number -26.8),("decimalPlaces",Number 10.0),("decimalMantissa",Number -2.68e11)])),("aismultiplier",Bool False),("astyle",Object (fromList [("ascommodityside",String "L"),("asdigitgroups",Null),("ascommodityspaced",Bool True),("asprecision",Number 1.0),("asdecimalpoint",String ".")]))])]],Array [String "expenses:food",String "expenses:food",Number 0.0,Array [Object (fromList [("aprice",Null),("acommodity",String "\8364"),("aquantity",Object (fromList [("floatingPoint",Number 26.8),("decimalPlaces",Number 10.0),("decimalMantissa",Number 2.68e11)])),("aismultiplier",Bool False),("astyle",Object (fromList [("ascommodityside",String "L"),("asdigitgroups",Null),("ascommodityspaced",Bool True),("asprecision",Number 1.0),("asdecimalpoint",String ".")]))])]]],Array [Object (fromList [("aprice",Null),("acommodity",String "\8364"),("aquantity",Object (fromList [("floatingPoint",Number 0.0),("decimalPlaces",Number 10.0),("decimalMantissa",Number 0.0)])),("aismultiplier",Bool False),("astyle",Object (fromList [("ascommodityside",String "L"),("asdigitgroups",Null),("ascommodityspaced",Bool True),("asprecision",Number 1.0),("asdecimalpoint",String ".")]))])]]
I see what you mean! Thanks for the bug report.
To clarify status: I had forgotten JSON output was implemented for several commands in the last release, https://hledger.org/release-notes.html#hledger-1-17. But as reported above, it was broken, showing haskell Read output instead of JSON.
Also: command help should be updated to list JSON as a supported output format where appropriate.
This is fixed in master, and will be in the june release.
Most helpful comment
This is fixed in master, and will be in the june release.