if (Object(cur) !== cur) {
// Primitives and null
} else if ($.isArray(cur)) {
// Array
} else {
// Object and everything else
}
switching to
if (typeof cur !== 'object') {
// Primitives
} else if (cur.constructor === Array){
// Array
} else if (cur.constructor === Object){
// Object
}
// null and everything else is ignored.
would produce valid JSON. In addition, you gain efficiency because you know what constructors to type check.
Efficiency not being the driver, do you want this extension to allow for invalid JSON? I'm torn personalty.
Valid
Pro: Efficiency
Con: End user doesn't have option for invalid.
Not valid
Pro: Gives end user option for invalid.
Con: Extension name is misnomer.
Url aside, as it is already pre-validated, using flatJSON presently allows for invalid JSON (
function
,new String()
,new RegExp()
,new Date()
, etc..)I.e.
would produce
because
switching to
would produce valid JSON. In addition, you gain efficiency because you know what constructors to type check.
Efficiency not being the driver, do you want this extension to allow for invalid JSON? I'm torn personalty.
Valid Pro: Efficiency Con: End user doesn't have option for invalid. Not valid Pro: Gives end user option for invalid. Con: Extension name is misnomer.