27
May
2006

JSON - better readable output

This is a modified version of JSON in JavaScript which adds an option to pretty print the JSON output.

Download: JSON-js-prettyPrint (js, 5 KB)

  object.toJSONString(prettyPrint)
  array.toJSONString(prettyPrint)
    prettyPrint ... if set to true the resulting string will be formated
                    with tabs and returns to be more human readable.
Here is an example data object:

   var data = {
      "eins" : "Eins",
      "int" : 2,
      "number" : 2.234,
      "obj" : {
         "a" : "A", b:"B", c:"C"
      },
      "array" : ["eins","zwei","drei",{"vier":4,"null":null,"undefined":undefined},{"vier":4,"null":null,"undefined":undefined},"zwei","drei",{"vier":4,"null":null,"undefined":undefined}],
      isBoolean : true
   };
data.toJSONString() will ouput:

{"array":["eins","zwei","drei",{"vier":4,"null":null},{"vier":4,"null":null},"zwei","drei",{"vier":4,"null":null}],"eins":"Eins","obj":{"a":"A","b":"B","c":"C"},"number":2.234,"isBoolean":true,"int":2}
data.toJSONString(true) will ouput:

{
	"array" : [
		"eins",
		"zwei",
		"drei",
		{
			"vier" : 4,
			"null" : null
		},
		{
			"vier" : 4,
			"null" : null
		},
		"zwei",
		"drei",
		{
			"vier" : 4,
			"null" : null
		}
	],
	"eins" : "Eins",
	"obj" : {
		"a" : "A",
		"b" : "B",
		"c" : "C"
	},
	"number" : 2.234,
	"isBoolean" : true,
	"int" : 2
}
why i did it?
on the client side it doesn't seem to make sense to pretty print the JSON output, because in most cases you will send it back to a server. but we use the script on the server side (using Helma/Rhino) so it makes perfectly sense for us.

Opera and WII

http://www.opera.com/pressreleases/en/2006/05/10/

exciting news. what that means is that in difference to other vendors (xbox 360) it will be possible to use wii as a cheap open web setop box - that is state-of-the-art and well documented. hopefully they will also support flash and/or video/audio embeding. everybody (not having a contract with nintendo) will be able to provide special formats and content for wii - personaly i think surfin' on a tv is the more useful scenario than browsing on a (slow and tiny) mobile.

click, click

http://www.w3.org/TR/html401/struct/links.html#adef-rel
http://www.w3.org/TR/html401/types.html#type-links
http://gmpg.org/xfn/11
http://www.w3.org/TR/html401/struct/global.html#profiles
logo

Mat's Blog

California Dreaming

Users Status

You are not logged in.

Search

 

Weather

Aktuelles Wetter in Kitzbuhel:


Temperatur: N/A C
UV Index: N/A
Luftfeuchte: N/A %
Sichtweite: N/A km
Luftdruck: N/A mb
Windstärke: N/A 

Weather data provided by weather.com

Get Firefox

Get Firefox!

Currently Reading


William Gibson, Jarreth Merz, Matthias Scherwenikas
Neuromancer, 3 Audio-CDs

Archive

May 2006
Sun
Mon
Tue
Wed
Thu
Fri
Sat
 
 1 
 2 
 6 
 7 
 9 
10
11
12
13
14
15
16
18
19
20
21
22
24
25
26
28
29
31
 
 
 
 

Recent Updates

but yammer accepts
no Austrian mobile numbers :(
cqeb - 15. Dec, 23:45
das verpasse ich leider......
das verpasse ich leider... http://twitter.com/flog/st atus/998712029
flog - 10. Nov, 21:38
bin schon sehr gespannt!...
bin schon sehr gespannt! bis dann
barbarao - 10. Nov, 15:59
hab mich auch gerade...
hab mich auch gerade angemeldet ;)
barbarao - 26. Aug, 10:57
minute 33 is auch sehr...
minute 33 is auch sehr interessant.
MasterOfDesaster - 7. Jul, 16:00
ja der Vortrag ist sehr...
ja der Vortrag ist sehr nett und zum testen kann man...
niepi - 4. Jul, 13:14
BTW: TrimJunction isn't...
BTW: TrimJunction isn't the Rhino port of Rails which...
robert42 - 27. Jun, 16:59
danke :)
danke :)
matthias - 5. Jun, 08:41

Status

Online for 1545 days
Last update: 15. Dec, 23:45

Credits

Knallgrau New Media Solutions - Web Agentur für neue Medien

powered by Antville powered by Helma


Creative Commons License

xml version of this page

twoday.net AGB