simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
3.01k stars 321 forks source link

--currency obedience for JSON reports #2260

Open MrPixelized opened 1 week ago

MrPixelized commented 1 week ago

I'm generating PDF reports based on hledger data, and the JSON report format is the most convenient for that (even though the way it serializes the data is a bit unpleasant to work with).

I'm finding that there's no way to adjust the precision on the floating point values, though as a user I was expecting there to be at least some way to obtain the values as they would be rendered in a regular hledger report, including overriding the formatting using -c.

Of course, there is also astyle. HOWEVER. Its values do not change when adjusting the precision using --commodity-style. It's also a bit inconvenient to use.

What would be a good way to help here?

One way that's backward-compatible is to add a hledgerRendered field or such to the aquantity field.

simonmichael commented 1 week ago

Thanks for the feedback on JSON output, we haven't many (known) users of that yet.

Yes, I think as you guessed our numbers in JSON output are intentionally a fixed machine-readable format, not affected by -c/--commodity-style which is mainly for human-/hledger-readable output.

Some related mentions in docs:

What kind of numbers would be more useful to you in the JSON ? Can you simply round them to lower precision ?

MrPixelized commented 6 days ago

In the end I decided to go from the CSV output to my own JSON format. What I would have really liked to see is human-readable content in a way that can be formatted from the command line. Doing all the formatting myself when there are other output formats that do it for you just was not worth it. Formatting also includes currency signs and such.

simonmichael commented 6 days ago

Are we talking about CSV output or JSON output ?

MrPixelized commented 5 days ago

We are talking about JSON output. CSV output gave me the data I wanted to have. It's just that as a (temporary) solution that was quicker than rolling my own rendering of the JSON output, I decided to go hledger -> csv -> json -> my thing instead.

simonmichael commented 5 days ago

Ok, that's totally fine. But I don't have a good understanding of the problems you mention. Here's how it seems to me:

If you'd like to share more specifics, please do. Maybe there are solutions or problems we're not seeing.