JavaScript should use native JSON parse/stringify for *Raw routines

Bug #1316245 reported by Bill Erickson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenSRF
Fix Released
Wishlist
Unassigned

Bug Description

Reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON

Browser Support:

http://caniuse.com/json

All modern browser support JSON.parse() and JSON.stringify(), which implements JSON handling natively in the browser. Though I have not confirmed this, I would assume that native parsing (likely implemented within the lower-level language of the browser) is faster and requires fewer resources than our JavaScript JSON parsing and stringifying routines. Using the native parser would also let us reduce (by a small amount) our JS code footprint.

Patch forthcoming to use JSON.parse and JSON.stringify as replacements for JSON2jsRaw and js2JSONRaw in JSON_v1.js. I'll leave the *Raw functions in place for now, though, until we confirm no code is accessing those directly.

===
 Do we need to support IE7? If so, we could alternatively check for the presence of window.JSON and only use it when it's available...
===

Note, we still need JSON_v1.js for encoding and decoding field-mapped objects. That section of the code will remain the same.

Tags: pullrequest
Revision history for this message
Bill Erickson (berick) wrote :

Actually, just confirmed that no OpenSRF or Evergreen code is directly access either of the *Raw functions, apart from their unit tests. If no objections, I'll remove those too...

Revision history for this message
Bill Erickson (berick) wrote :

Code pushed to remove the *Raw() functions:

http://git.evergreen-ils.org/?p=working/OpenSRF.git;a=shortlog;h=refs/heads/user/berick/lp1316245-js-use-native-json

The patch also removes jsonPretty(), which no code was using (in OpenSRF or Evergreen). For pretty printing, use instead:

JSON.stringify(obj, null, /* tab spaces */ 2)

tags: added: pullrequest
Changed in opensrf:
milestone: none → 2.4.0-alpha
Revision history for this message
Galen Charlton (gmc) wrote :

Pushed to master. Thanks, Bill!

Changed in opensrf:
status: New → Fix Committed
Galen Charlton (gmc)
Changed in opensrf:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.