json - 使用路径访问 json 中的深度键并使用给定参数更新它
问题描述
我有一个嵌套的 json 对象,我有一个路径列表(模式在下面给出),我想根据路径动态更改一些值,其余对象保持不变。我们有样本数据:
export const newTemplate = {
"patientInfo": {
"name": ".document.author.name.given",
"address": [
{
"country": "pakistan",
"city": "rawalpindi",
"disease": [
{
"id": 'HX-12',
"name": "Flu"
},
{
"id": 'HX-12',
"name": "Fever"
}
]
}
],
"phone": ".document.author.phone",
"document": {
"name": ".document.documentation_of[0].name"
}
},
"location": ".document.location",
"allergies": ".allergies",
"commonInfo": {
"common": {
"allergies": ".allergies",
}
}
}
我们有一条路
const path = .patientInfo.address[0].disease[1].name
我想通过这条路径将“名称”Fever 更改为 Dhairiya
`${newTemplate}${path}` = "Dhairiya"
// it will become like this.
// newTemplate.patientInfo.address[0].disease[1].name = "Dhairiya"
解决方案
推荐阅读
- pandas - panda read_html 忽略
并连接字符串 - php - 当我将文件上传到服务器时,如何获取文件名?
- django - 如何使用 django google-auth 授权我的 API 请求?
- java - Docker + Springboot + postgres + JHipster = org.postgresql.util.PSQLException:连接尝试失败
- json - 如何在 JSON 中添加对象数组
- php - 将数据从 unity3d 游戏发送到 PHP 空变量
- c# - 如何检查用户是否获胜?
- swift - 如何在列表视图中更改项目的顺序?
- node.js - nodejs动态增加JSON对象属性而不会在第一次尝试时得到未定义
- xml - 这个 XML 文档做得好吗?