Skip to content

Commit 0fea7d7

Browse files
committed
Adding and fixing case "multiple object members".
* A space sneaked into the join() command, removing here to match the test case * Rebuilding .min.js
1 parent b2b0048 commit 0fea7d7

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/jquery.json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
val = $.toJSON( o[k] );
124124
pairs.push(name + ':' + val);
125125
}
126-
return '{' + pairs.join(', ') + '}';
126+
return '{' + pairs.join(',') + '}';
127127
}
128128
};
129129

src/jquery.json.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ return'['+ret.join(',')+']';}
1919
var name,val,pairs=[];for(var k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
2020
if(typeof o[k]==='function'){continue;}
2121
val=$.toJSON(o[k]);pairs.push(name+':'+val);}
22-
return'{'+pairs.join(', ')+'}';}};$.evalJSON=function(src){if(typeof JSON==='object'&&JSON.parse){return JSON.parse(src);}
22+
return'{'+pairs.join(',')+'}';}};$.evalJSON=function(src){if(typeof JSON==='object'&&JSON.parse){return JSON.parse(src);}
2323
return eval('('+src+')');};$.secureEvalJSON=function(src){if(typeof JSON==='object'&&JSON.parse){return JSON.parse(src);}
2424
var filtered=src.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)){return eval('('+src+')');}else{throw new SyntaxError('Error parsing JSON, source is not valid.');}};$.quoteString=function(string){if(string.match(escapeable)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c;}
2525
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}

test/jquery.json.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ test( 'Basic toJSON usage', function(){
2727
'{"apple":{"apple":2}}',
2828
'Objects inside objects'
2929
);
30+
equalJSON(
31+
{ apple: 7, pear: 5 },
32+
'{"apple":7,"pear":5}',
33+
'Objects with multiple members should be separated by a comma'
34+
);
3035
equalJSON(
3136
2.5,
3237
'2.5',

0 commit comments

Comments
 (0)