How to save a histogram to JSON

Hello All,
I am trying to save a histogram to a JSON object and I have gotten thus far:

...
hist->Draw();
TString json = TBufferJSON::ToJSON(hist);
...

I am now unsure about how to save this to a file.
I see the documentation has TBufferJSON::ExportToFile function but can’t see any example of how to use it. Can anyone show me how to write this json to file?

Thanks


ROOT Version: 6.28/06
Platform: Linux
Compiler:


I’m sure @linev can help you

Just do:

hist->Draw();
TBufferJSON::ExportToFile("hist.json", hist);

You also can use SaveAs method:

hist->SaveAs("hist.json");
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.