本文介绍了无法使用 jolt 解析器将一种 json 形式转换为另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 data 如下所示:

{"resourceType": "免疫","id": "示例",协议应用":[{"系列": "2 剂",权威": {"reference": "组织/org1","type": "组织","display": "xyz 组织"},目标疾病":[{编码":[{"system": "http://snomed.info/sct",代码":40468003"}]}],"doseNumberPositiveInt": 1,seriesDosesPositiveInt":10},{"系列": "3 剂",目标疾病":[{编码":[{"system": "http://snomed.info/sct",代码":66071002"}]}],"doseNumberString": "一","seriesDosesString": "十"}]}

我需要对其进行转换以获得以下输出:

[ {"resourceType": "免疫",系列":2 剂","reference" : "组织/org1","type": "组织","display": "xyz 组织","targetDiseaseCodingSystem":"http://snomed.info/sct"目标疾病代码":40468003""doseNumberPositiveInt" : 1,seriesDosesPositiveInt":10}, {"resourceType": "免疫",系列":3 剂","targetDiseaseCodingSystem":"http://snomed.info/sct"目标疾病代码":66071002""doseNumberString" : "一","seriesDosesString" : "十"]]

以下是我的spec:

[{"操作": "移位",规格":{协议应用":{*":{"@(2,resourceType)": "[#2].resourceType",权威": {//"参考": "参考""*": "[#3].&"},目标疾病":{*":{编码":{*":{//"*": "[#2].&""@(2,system)": "[#2].targetDiseaseCodingSystem"}}}},"*": "[#2].&"}}}}]

应用上述规范后,我的输出低于输出:

[ {"resourceType": "免疫",系列":2 剂","reference" : "组织/org1","type" : "组织","display": "xyz 组织","doseNumberPositiveInt" : 1,seriesDosesPositiveInt":10}, {"resourceType": "免疫",系列":3 剂","doseNumberString" : "一","seriesDosesString" : "十"]]

其中未填充 targetcodingsystemtargetdiseasecode.请帮我解决这个问题.

解决方案

下面的规范会有所帮助,

使用[&n],将上面的n值对象移动.

[{"操作": "移位",规格":{协议应用":{*":{"@(2,resourceType)": "[&1].resourceType",权威": {"*": "[&2].&"},目标疾病":{*":{编码":{*":{"system": "[&5].targetDiseaseCodingSystem","code": "[&5].targetDiseaseCode"}}}},"*": "[&1].&"}}}}]

I have a data like below:

{
  "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"
    }
  ]
}

I need to transform it to get the below output:

[ {
  "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"
} ]

Below is my spec:

[
  {
    "operation": "shift",
    "spec": {
      "protocolApplied": {
        "*": {
          "@(2,resourceType)": "[#2].resourceType",
          "authority": {
            // "reference": "reference"
            "*": "[#3].&"
          },
          "targetDisease": {
            "*": {
              "coding": {
                "*": {
                  //"*": "[#2].&"
                  "@(2,system)": "[#2].targetDiseaseCodingSystem"
                }
              }
            }
          },
          "*": "[#2].&"
        }
      }
    }
    }

]

I am getting below output after applying above spec:

[ {
  "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"
} ]

Where targetcodingsystem and targetdiseasecode is not populated. Please help me in this.

解决方案

Below is spec would help,

Use [&n], to shift the value n object above.

[
  {
    "operation": "shift",
    "spec": {
      "protocolApplied": {
        "*": {
          "@(2,resourceType)": "[&1].resourceType",
          "authority": {
            "*": "[&2].&"
          },
          "targetDisease": {
            "*": {
              "coding": {
                "*": {
                  "system": "[&5].targetDiseaseCodingSystem",
                  "code": "[&5].targetDiseaseCode"
                }
              }
            }
          },
          "*": "[&1].&"
        }
      }
    }
    }
]

这篇关于无法使用 jolt 解析器将一种 json 形式转换为另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 00:40