Maintain Order in JSON Import

Sannyasin Brahmanathaswami brahma at hindu.org
Wed Sep 14 17:18:05 EDT 2016


Monte Goulding wrote:

try

    "colorwheel": [
                                {
                                   “name”: “Red”,
                                    “color”: “255,0,0"
                                },


FYI, further tests with jsonImport/Export round trips, reading and writing:

jsonImport 
jsonExport

are 

a) not in the dictionary for     
b) round trip does not support any formatting (no indentation or vertical white space)
c) square braces not supported on export.

Valid JSON going in:


{
	"settings": {
		"global": "",

		"modules":

		{
			"colormeds": 
				{"breathCount": "1",
				"cycle": "1",
				"currentLevel": "1",
				"breathRate": "1"
				}
		}
	}
}



gets written out as:  a single line

{"settings": {"global": "","modules": {"colormeds": {"1": {"breathCount": "1","cycle": "1","currentLevel": "1","breathRate": "1"}}}}}

AND

Square brace notation is not supported, but converted to explicit numeric keys
--not a big problem, but good to be aware that

this goes in:	

{
	"settings": {
		"global": "",

		"modules":

		{
			"colormeds": 
			[
			{
				"breathCount": "1",
				"cycle": "1",
				"currentLevel": "1",
				"breathRate": "1"
				}
			]
		}
	}
}

and comes out as

{"settings": {"global": "","modules": {"colormeds": {"1": {"breathCount": "1","cycle": "1","currentLevel": "1","breathRate": "1"}}}}}

which, formatted looks like:

{
	"settings": {
		"global": "",
		"modules": {
			"colormeds": {
				"1": {
					"breathCount": "1",
					"cycle": "1",
					"currentLevel": "1",
					"breathRate": "1"
				}
			}
		}
	}
}

Actually I find it easier to wrap my brain around the latter… though it would be nice if the output were formatted.  Does anyone have a JSON formatter function I can pass this thru before writing to disk?

BR
 



More information about the use-livecode mailing list