Jolt:如何合并来自不同数组的一个数组元素
Jolt: How to merge in one array elements from different arrays
我正在尝试合并数组中不同元素的内容。
我的 jSon 看起来像这样:
{
"Messages": {
"test": "test1",
"CreditCheck": [
{
"name": "Credit Score",
"score": 15,
"percentage": 20
},
{
"name": "Cards Score",
"score": 15,
"percentage": 20
},
{
"name": "Bank Score",
"score": 20,
"percentage": 20
}
]
}
}
我目前的 Jolt 规格是这个:
[
{
"operation": "shift",
"spec": {
"*": {
"test": "myTesting",
"CreditCheck": {
"*": {
"name": "creditName.[]",
"score": "creditScore.[]"
}
}
}
}
}
]
我得到以下信息:
{
"myTesting" : "test1",
"creditName" : [ "Credit Score", "Cards Score", "Bank Score" ],
"creditScore" : [ 15, 15, 20 ]
}
但我需要实现的是:
{
"myTesting" : "test1",
"creditNames&Scores" : [ "Credit Score": 15, "Cards Score": 15, "Bank Score": 20 ],
}
“CreditCheck”结构中没有预定义数量的元素,因此我试图尽可能动态地做到这一点。
在此先感谢您的帮助,最好!
此规范应该适合您:
[
{
"operation": "shift",
"spec": {
"*": {
"test": "myTesting",
"CreditCheck": {
"*": {
"score": "creditNames\&Scores[].@(1,name)"
}
}
}
}
}
]
输出:
{
"myTesting" : "test1",
"creditNames&Scores" : [ { "Credit Score" : 15 }, { "Cards Score" : 15 }, { "Bank Score" : 20} ]
}
备注:
- 输出中的元素必须用大括号括起来才能使它们有效 json 个对象
\
用于转义符号&
- 使用 https://jolt-demo.appspot.com/ where you can also find the example of the advanced
@
wildcard 用法进行测试
我正在尝试合并数组中不同元素的内容。
我的 jSon 看起来像这样:
{
"Messages": {
"test": "test1",
"CreditCheck": [
{
"name": "Credit Score",
"score": 15,
"percentage": 20
},
{
"name": "Cards Score",
"score": 15,
"percentage": 20
},
{
"name": "Bank Score",
"score": 20,
"percentage": 20
}
]
}
}
我目前的 Jolt 规格是这个:
[
{
"operation": "shift",
"spec": {
"*": {
"test": "myTesting",
"CreditCheck": {
"*": {
"name": "creditName.[]",
"score": "creditScore.[]"
}
}
}
}
}
]
我得到以下信息:
{
"myTesting" : "test1",
"creditName" : [ "Credit Score", "Cards Score", "Bank Score" ],
"creditScore" : [ 15, 15, 20 ]
}
但我需要实现的是:
{
"myTesting" : "test1",
"creditNames&Scores" : [ "Credit Score": 15, "Cards Score": 15, "Bank Score": 20 ],
}
“CreditCheck”结构中没有预定义数量的元素,因此我试图尽可能动态地做到这一点。
在此先感谢您的帮助,最好!
此规范应该适合您:
[
{
"operation": "shift",
"spec": {
"*": {
"test": "myTesting",
"CreditCheck": {
"*": {
"score": "creditNames\&Scores[].@(1,name)"
}
}
}
}
}
]
输出:
{
"myTesting" : "test1",
"creditNames&Scores" : [ { "Credit Score" : 15 }, { "Cards Score" : 15 }, { "Bank Score" : 20} ]
}
备注:
- 输出中的元素必须用大括号括起来才能使它们有效 json 个对象
\
用于转义符号&
- 使用 https://jolt-demo.appspot.com/ where you can also find the example of the advanced
@
wildcard 用法进行测试