0

Is there any way to change a single value in an already existing JSON file with JSONcpp? I want to preserve the existing formatting (comments, spaces, line breaks) in the file.

Example: find the value with key "test_boolean" in C:/test.json and make its value "false", leaving everything else as it is.

I've tried using Json::StyledStreamWriter, both with the root of the value I want to change, and the value itself. In the first case, the entire file was rewritten, with the new value, but no formatting or comments were preserved. In the second case, only "false" was written in the entire file.

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
  • @Cornstalks I've tried using Json::StyledStreamWriter, both with the root of the value I want to change, and the value itself. In the first case, the entire file was rewritten, with the new value, but no formatting or comments were preserved. In the second case, only "false" was written in the entire file. – Vittorio Romeo Jan 07 '13 at 17:21
  • This is just a suggestion as I have not tried it myself. Could you try and read the JSON, store it locally whilst changing the value, and then rewrite a new output file which is equal to the input one but with one value changed? – Francesco Perticarari Dec 26 '17 at 09:54

1 Answers1

-1

According to my tests/research, it is impossible to modify a single value in a JSON maintaining the current formatting, using JSONcpp.

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416