Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 07:22 PM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    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

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, thanks
    I'm using PHP to interpret the JSON objects, so multi-lines seem to work (with \n).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •