Created
March 8, 2017 13:07
-
-
Save flexdevguy/e111a4b00f854ddf77bb50ed3f0dbf2d to your computer and use it in GitHub Desktop.
JSON ignore key case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var obj = { | |
| "containerIsArchived": "Null", | |
| "containerOrderNo": "26", | |
| "versionNum": "0", | |
| "versionnum": "01", | |
| "containerGlobalUniqueId": "Null", | |
| "containerIsTenantBased": "true", | |
| "containerCreatedBy": "user", | |
| "containerIsDeleted": "false", | |
| "containerTenantId": "292FEC76-5F1C-486F-85A5-09D88096F098", | |
| "containerLayoutId": "4e13dfcd-cd3b-4a29-81bd-0f73cf9577cf", | |
| "containerApplicationId": "0000000-0000-0000-0000-000000000000", | |
| "containerIsActive": "Null", | |
| "containerHeaderText": "apitest19feb16", | |
| "containerId": "3745b273-c48d-4c94-b576-3d7aac2f7ac6", | |
| "containerCreatedUTCDate": "2016-02-19 17:57:51.0" | |
| }; | |
| ------------------------------- | |
| var key, keys = Object.keys(obj); | |
| var n = keys.length; | |
| var objArr=[] | |
| while (n--) { | |
| objArr.push(keys[n].toLowerCase()); | |
| } | |
| --------------------------------- | |
| console.time('start'); | |
| var key, keys = Object.keys(obj); | |
| var n = 0; | |
| var newobj={} | |
| while (n < keys.length) { | |
| n++; | |
| key = keys[n]; | |
| newobj[key.toLowerCase()] = obj[key]; | |
| } | |
| console.timeEnd('start'); | |
| -------------------------------------- | |
| function ConvertKeysToLowerCase(obj) { | |
| var output = {}; | |
| for (i in obj) { | |
| if (Object.prototype.toString.apply(obj[i]) === '[object Object]') { | |
| output[i.toLowerCase()] = ConvertKeysToLowerCase(obj[i]); | |
| }else if(Object.prototype.toString.apply(obj[i]) === '[object Array]'){ | |
| output[i.toLowerCase()]=[]; | |
| output[i.toLowerCase()].push(ConvertKeysToLowerCase(obj[i][0])); | |
| } else { | |
| output[i.toLowerCase()] = obj[i]; | |
| } | |
| } | |
| return output; | |
| }; | |
| var fault = Ext.JSON.decode(JSON.stringify(fault).replace(/"([^"]+)":/g,function($0,$1){return ('"'+$1.toLowerCase()+'":');})), | |
| JSON.stringify(obj).replace(/"([^"]+)":/g,function($0,$1){return ('"'+$1.toLowerCase()+'":');}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment