首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用jolt解析器将一个json表单转换为另一个json表单

无法使用jolt解析器将一个json表单转换为另一个json表单
EN

Stack Overflow用户
提问于 2020-06-04 09:24:39
回答 1查看 63关注 0票数 0

我有一个data,如下所示:

代码语言:javascript
运行
复制
{
  "resourceType": "Immunization",
  "id": "example",
  "protocolApplied": [
    {
      "series": "2-dose",
      "authority": {
        "reference": "Organization/org1",
        "type": "Organization",
        "display": "xyz organization"
      },
      "targetDisease": [
        {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "40468003"
            }
          ]
        }
      ],
      "doseNumberPositiveInt": 1,
      "seriesDosesPositiveInt": 10
    },
    {
      "series": "3-dose",
      "targetDisease": [
        {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "66071002"
            }
          ]
        }
      ],
      "doseNumberString": "one",
      "seriesDosesString": "ten"
    }
  ]
}  

我需要对其进行转换,以获得以下output

代码语言:javascript
运行
复制
[ {
  "resourceType" : "Immunization",
  "series" : "2-dose",
  "reference" : "Organization/org1",
  "type" : "Organization",
  "display" : "xyz organization",
  "targetDiseaseCodingSystem":"http://snomed.info/sct"
  "targetDiseaseCode":"40468003"
  "doseNumberPositiveInt" : 1,
  "seriesDosesPositiveInt" : 10
}, {
  "resourceType" : "Immunization",
  "series" : "3-dose",
   "targetDiseaseCodingSystem":"http://snomed.info/sct"
  "targetDiseaseCode": "66071002"
  "doseNumberString" : "one",
  "seriesDosesString" : "ten"
} ]  

下面是我的spec

代码语言:javascript
运行
复制
[
  {
    "operation": "shift",
    "spec": {
      "protocolApplied": {
        "*": {
          "@(2,resourceType)": "[#2].resourceType",
          "authority": {
            // "reference": "reference"
            "*": "[#3].&"
          },
          "targetDisease": {
            "*": {
              "coding": {
                "*": {
                  //"*": "[#2].&"
                  "@(2,system)": "[#2].targetDiseaseCodingSystem"
                }
              }
            }
          },
          "*": "[#2].&"
        }
      }
    }
    }

]

在应用上述规范之后,我的输出低于预期:

代码语言:javascript
运行
复制
[ {
  "resourceType" : "Immunization",
  "series" : "2-dose",
  "reference" : "Organization/org1",
  "type" : "Organization",
  "display" : "xyz organization",
  "doseNumberPositiveInt" : 1,
  "seriesDosesPositiveInt" : 10
}, {
  "resourceType" : "Immunization",
  "series" : "3-dose",
  "doseNumberString" : "one",
  "seriesDosesString" : "ten"
} ]

其中没有填充targetcodingsystemtargetdiseasecode。请帮我这个忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-04 11:35:42

下面是规范会有帮助的,

使用[&n]转换上面的值n对象。

代码语言:javascript
运行
复制
[
  {
    "operation": "shift",
    "spec": {
      "protocolApplied": {
        "*": {
          "@(2,resourceType)": "[&1].resourceType",
          "authority": {
            "*": "[&2].&"
          },
          "targetDisease": {
            "*": {
              "coding": {
                "*": {
                  "system": "[&5].targetDiseaseCodingSystem",
                  "code": "[&5].targetDiseaseCode"
                }
              }
            }
          },
          "*": "[&1].&"
        }
      }
    }
    }
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62191179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档