Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-15-2008, 04:19 PM   PM User | #1
Zegg90
New Coder

 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Zegg90 is an unknown quantity at this point
Is this valid JSON?

I am new to JSON, so I am just trying stuff out for my PHP application before I use it.

I have a question, is this valid JSON?

Code:
{"name": "Test Package", /* Required or 'Untitled' (default value) */
"author": "Zeggy", /* Optional, maybe a default value */
"version": 1.1, /* Version, must be a number */
"actions": [
	{
		"name": "Adding test code", /* Name for this particular process, required */
		"file": "edit_me.php", /* Required */
		"action": "add", /* choose out of [add, remove, replace], is required */
		"type": "before", /* before, after */
		"where": "$test = \"123321\";", /* Code to search for */
		"code": "blabla
			blabla
			more code" /*Code to add/remove/replace */
	},
	{
		"name": "Removing a comment",
		"file": "another_file.php", /* Required */
		"action": "remove",
		"code": "\/\/This is a PHP comment!\\n" /* Removing this comment, 'where' not required */
	},
	{
		"name": "Replacing $var1",
		"file": "replace.php", /* Required */
		"action": "replace",
		"where": "$var1 = \"var numba 1\";", /* Find this string */
		"code": "$var2 = \"new var #2\";" /* Replace with this */
	}
]
}

Would this work if I used PHP to change it into an object/array?
And are the comments allowed?
Any other observations?

Thanks!

Last edited by Zegg90; 01-15-2008 at 06:22 PM..
Zegg90 is offline   Reply With Quote
Old 01-15-2008, 06:17 PM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
Quote:
Originally Posted by Zegg90 View Post
Code:
{"package": {
	"name": "Test Package", /* Required or 'Untitled' (default value) */
	"author": "Zeggy", /* Optional, maybe a default value */
	"version": 1.1, /* Version, must be a number */
	"actions": [
		{
			"name": "Adding test code", /* Name for this particular process, required */
			"file": "edit_me.php", /* Required */
			"action": "add", /* choose out of [add, remove, replace], is required */
			"type": "before", /* before, after */
			"where": "$test = \"123321\";", /* Code to search for */
			"code": "blabla
				blabla
				more code" /*Code to add/remove/replace */
		},
		{
			"name": "Removing a comment",
			"file": "another_file.php", /* Required */
			"action": "remove",
			"code": "\/\/This is a PHP comment!\\n" /* Removing this comment, 'where' not required */
		},
		{
			"name": "Replacing $var1",
			"file": "replace.php", /* Required */
			"action": "replace",
			"where": "$var1 = \"var numba 1\";", /* Find this string */
			"code": "$var2 = \"new var #2\";" /* Replace with this */
		}
	]
}}
its valid json...comments are allowed...except for the portion highlighted in red...strings in javascript have to be terminated in the same line...but both IE and FF allow the C style continutation using the \

so, u can either write
Code:
"code": "blabla blabla more code"
or
Code:
"code": "blabla\
				blabla\
				more code"
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 01-15-2008, 07:07 PM   PM User | #3
Zegg90
New Coder

 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Zegg90 is an unknown quantity at this point
Okay, thanks
I'm using PHP to interpret the JSON objects, so multi-lines seem to work (with \n).
Zegg90 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05 AM.


Advertisement
Log in to turn off these ads.