Reputation: 764
I have a multidimensional JSON data set that need multiple values replaced so that I can load my application to the web for some troubleshooting. The values need to be replaced because they are private records that may identify individuals' protected medical information. I suck at regex and have yet to be able to do this efficiently. What is want is to replace the following fields as described in the ():
PROV_NAME (Drlastname001, Drfirstname001 with # portion incrementing) PAT_NAME (Patlname0001 , Patfname0001 with # portion incrementing) PERS_ID, MRN, ENC_ID, FIN, ORD_ID (random # for each) HOME_PHONE, CELL_PHONE (random ph #) CMT_PRSNL (Stflastn0001 , Stffirstn0001 with # portion incrementing)
Below is a sample of the JSON dataset with the information manually replace. My real data set has multiple items for most of the arrays []. I was trying to do this in Sublime Text but once again I suck at regex. How can I do this quickly? PHP, JavaScript, within Sublime Text?
{
"TICKLER_ORDERED": {
"PROVIDER": [
{
"PROV_NAME": "Drlastname001, Drfirstname001",
"PERSON": [
{
"PERS_ID": 234213423,
"PAT_NAME": "Patlname0001 , Patfname0001",
"MRN": "45246",
"HOME_PHONE": "984-435-5673",
"CELL_PHONE": "745-547-6544",
"OLDEST_ORDER": "/Date(2012-01-03T13:34:28.000-04:00)/",
"ENCOUNTERS": [
{
"ENC_ID": 8854774,
"FIN": "78787457",
"ORDERS": [
{
"ORD_ID": 23423413,
"ORD_NAME": "MA Digital Diagnostic Mammo-Bil/CAD",
"ORD_TYPE": "Radiology",
"ORD_STATUS": "Canceled",
"ORD_PRIORITY": "Routine",
"ORD_DATE": "01/03/2012 13:34",
"DUE_DATE": "01/06/2012 13:00",
"COMMENTS": [
{
"CMT_DISP": "This is a test",
"SEQUENCE": "1",
"CMT_DTTM": "02/04/13 11:40",
"CMT_PRSNL": "Stflastn , Stffirstn"
},
{
"CMT_DISP": "This isn't a test",
"SEQUENCE": "2",
"CMT_DTTM": "02/04/13 11:42",
"CMT_PRSNL": "Stflastn0001 , Stffirstn0001"
}
]
},
{
"ORD_ID": 123234235,
"ORD_NAME": "US Breast Bilateral",
"ORD_TYPE": "Radiology",
"ORD_STATUS": "Canceled",
"ORD_PRIORITY": "Routine",
"ORD_DATE": "01/03/2012 13:34",
"DUE_DATE": "01/06/2012 14:20",
"COMMENTS": []
}
]
}
]
}
]
}
]
}
}
Upvotes: 0
Views: 140
Reputation: 308
PHP provides great tools for iterating over an array of JSON data. As adeneo suggests, json_decode and json_encode will let you convert your data from JSON to a PHP multi-dimensional array, and back to JSON, respectively. Once you have your data in a PHP array, iterate over that array and use your knowledge of its structure, simple regular expressions (something like '/[0-9]{3}$/'), and counter variables to appropriately increase the indices.
Upvotes: 1