1. Igor Perisic
  2. PowerBuilder
  3. Wednesday, 11 January 2023 18:48 PM UTC

Hi,

I want to keep the original .json formatting when setting a value to my .json. 

My original .json file

After running my code, it puts everything on a single line.

 

My code

jsonString = create JsonPackage
checkError = jsonString.LoadFile(Appl + ".json")

if Len(checkError) = 0 then
	result = jsonString.SetValue("maxRows","50", false)
	if result = 1 then
		jsonString.SaveToFile(Appl + ".json", EncodingANSI!)
	end if
end if
destroy jsonString

 

The .json still works after being all on one line but would like to keep the format if possible for easy readability. 

 

Thanks

 

Accepted Answer
Daryl Foster Accepted Answer Pending Moderation
  1. Wednesday, 11 January 2023 23:36 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Igor, how are you viewing your json?  Formatting doesn't matter for applications that consume json, and the formatting adds extra data that needs to be transmitted and parsed, but as you say it's much easier to read if it is formatted correctly. When viewing json I sometimes use Notepad++ with a JSON Viewer plugin, but lately I've been using DevToys (https://devtoys.app/) which has a great json formatter.

Comment
  1. Miguel Leeuwe
  2. Thursday, 12 January 2023 04:07 AM UTC
(BTW, I'm using that extension in Google Chrome)
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 12 January 2023 04:09 AM UTC
  1. Helpful
  1. Igor Perisic
  2. Thursday, 12 January 2023 17:47 PM UTC
Thanks Miguel I'll check those out! I've been using VSCode to view my JSONs
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.