我有一个多维JSON数据集需要替换多个值,以便我可以将我的应用程序加载到Web进行一些故障排除。需要更换这些值,因为它们是可以识别个人受保护医疗信息的私人记录。我吮吸正则表达式并且还没有能够有效地做到这一点。想要的是替换()中描述的以下字段:
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)
以下是手动替换信息的JSON数据集示例。我的真实数据集对于大多数数组[]有多个项目。我试图在Sublime Text中做到这一点,但我再次吮吸正则表达式。我该怎么办?在Sublime Text中的PHP,JavaScript?
{
"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": []
}
]
}
]
}
]
}
]
}
}
答案 0 :(得分:1)
PHP为迭代JSON数据数组提供了很好的工具。正如adeneo建议的那样,json_decode和json_encode将允许您将数据从JSON转换为PHP多维数组,并分别转换回JSON。一旦你的数据在PHP数组中,迭代该数组并使用你的结构知识,简单的正则表达式(类似'/ [0-9] {3} $ /')和计数器变量来适当增加指数。