New issue
Advanced search Search tips

Issue 626949 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

JSON.parse not parsing correctly

Reported by anto...@gmail.com, Jul 10 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41

Steps to reproduce the problem:
1. create the following as a string:
{ "favorite": { "name": "Test Page", "url": "www.test.com" }, "folder": { "name": "A Category", "subfavorite": [{ "name": "Another Page", "url": "www.test.com" }, { "name": "3rd Page", "url": "www.test.com" }] }, "favorite": { "name": "4th Page", "url": "www.tomorrow.com" } }

e.g.

jsonStr = '{ "favorite" : { "name":"Test Page" , "url":"www.test.com" },' +
                                          '"folder": { "name":"A Category",' +
                                              '"subfavorite": [' + 
                                                                '{ "name":"Another Page" , "url":"www.test.com" },' +
                                                                '{ "name":"3rd Page" , "url":"www.test.com" }' +
	                                                        '] },' +
                                          '"favorite":{ "name":"4th Page" , "url":"www.tomorrow.com" } }'

2. run the following code on it:

alert(jsonStr);
var jsonData = JSON.parse(jsonStr);
var str = JSON.stringify(jsonData);
alert(str);

3. The order is reversed, and the first favorite "test page" is missing entirely

What is the expected behavior?
It should give the exact same string as we started from. The same nodes and preferably same order.

What went wrong?
I believe it is parse and not stringify that is cause of the error.

Did this work before? N/A 

Chrome version: 51.0.2704.106  Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: 

tested on opera 38 and chrome 51
 

Comment 1 by anto...@gmail.com, Jul 10 2016

I have run the json through a validator. however, if the implementation does not see it as valid, it should throw a parse error e.g. duplicate key error.

Comment 2 by tkent@chromium.org, Jul 11 2016

Components: -Blink Blink>JavaScript

Comment 3 by pxinc...@gmail.com, Jul 11 2016

in your testcase ,
it two 'favorite',
I think the 'favorite' should be key. The second will replace the first. 
Status: WontFix (was: Unconfirmed)
See #3. Double entry of 'favorite' produces this problem.

Comment 5 by anto...@gmail.com, Jul 11 2016

I know there is a duplicate entry. that is the point!

could you reger to a specification saying a silent overwrite is OK? IMHO it should at least throw an error, or have a setting, overwrite, add duplicate key, throw error.

Sign in to add a comment