Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--currency obedience for JSON reports #2260

Open
MrPixelized opened this issue Oct 13, 2024 · 8 comments
Open

--currency obedience for JSON reports #2260

MrPixelized opened this issue Oct 13, 2024 · 8 comments
Labels
docs Documentation-related. json hledger json output format, or JSON produced/consumed by hledger-web.

Comments

@MrPixelized
Copy link

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 simonmichael added the json hledger json output format, or JSON produced/consumed by hledger-web. label Oct 14, 2024
@simonmichael
Copy link
Owner

simonmichael commented Oct 14, 2024

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 ?

@simonmichael simonmichael added the docs Documentation-related. label Oct 14, 2024
@MrPixelized
Copy link
Author

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
Copy link
Owner

Are we talking about CSV output or JSON output ?

@MrPixelized
Copy link
Author

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
Copy link
Owner

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:

  • json output provides numbers with up to 10 decimal places. When reading JSON, I imagine you are usually in a programming language and can easily reformat those numbers.
  • csv output provides machine-readable numbers, which I believe are still somewhat customizable with -c/--commodity-style. TSV is also available.
  • text output provides human-readable numbers, with extreme customisability from the command line.

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

@MrPixelized
Copy link
Author

Well, the assumption "When reading JSON, I imagine you are usually in a programming language and can easily reformat those numbers." doesn't quite hold. Yes, I am in a programming language, and I could reformat those numbers, but it's actually quite a bit of extra implementation on top of what's otherwise just reading a block of extremely easily digestable data (in JSON) and making a report out of it. In my case, it was less work to use CSV as an intermediate and convert it to JSON than to implement the formatting. So, in a case where I might be forced to use JSON, another output format was still preferred.

@simonmichael
Copy link
Owner

I’m trying to find out, not to assume anything. :)

Long story short, are you saying it would be better for everyone if json numbers respected —-commodity-style ?

@MrPixelized
Copy link
Author

I can't speak for everyone, but it would have helped my case if there would be (alongside the machine-targeted data), strings provided that behave as what would otherwise be presented to humans (e.g. the default output format).

Thanks for your engagement with this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation-related. json hledger json output format, or JSON produced/consumed by hledger-web.
Projects
None yet
Development

No branches or pull requests

2 participants