JSON to JSON changing array to one long string using JOLT

六眼飞鱼酱① 提交于 2019-12-11 12:56:27

问题


Lets say my json is:

{
 "rating": {
  "primary": {
   "value": ["a","B",1]
  }
 }
}

What I want to achieve is:

{
 "values": "a, B, 1"
}

I'm using jolt json to json code.


回答1:


It is not possible with stock transformations of Jolt. You need to write your custom transformation. Check the documentation section on how to write your own transformations.




回答2:


you can try the following spec

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "value": "=concat(@(2,rating.primary.value[0]),',',@(2,rating.primary.value[1]),',',@(2,rating.primary.value[2]))"
    }
  },
  {
    "operation": "remove",
    "spec": {
      "rating": ""
    }
  }

]


来源:https://stackoverflow.com/questions/35707768/json-to-json-changing-array-to-one-long-string-using-jolt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!