【发布时间】:2020-12-20 15:54:39
【问题描述】:
我刚开始学习颠簸变换。我发现了这种情况。该规范也已发布,但我试图理解规范,并与使用“&”的字段级别混淆。 从以下规格: 我对这种语法“name”感到困惑:“state[&3].cities[&1].cityname”。 为什么 "name": "state[&2].cities[&1].cityname" 没有给出任何输出?据我了解,城市名称的状态级别是&2。有人可以尝试解释为什么使用 &3。
Input Json:
{
"country": "usa",
"state": [
{
"stateName": "TX",
"location": "south",
"cities": [
{
"name": "Austin",
"pop": "1M"
},
{
"name": "Dallas",
"pop": "2M"
}
]
},
{
"stateName": "CA",
"location": "west",
"cities": [
{
"name": "SanFran",
"pop": "3M"
},
{
"name": "LosAngeles",
"pop": "4M"
}
]
}
]
}
Expected Output:
{
"country": "usa",
"state": [
{
"stateName": "TX",
"locatedIn": "south", // name change here
"cities": [
{
"cityname": "Austin", // name change here
"citypopulation": "1M" // name change here
},
{
"cityname": "Dallas",
"citypopulation": "2M"
}
]
},
{
"stateName": "CA",
"locatedIn": "west",
"cities": [
{
"cityname": "SanFran",
"pop": "3M"
},
{
"cityname": "LosAngeles",
"citypopulation": "4M"
}
]
}
]
}
Spec:
[
{
"operation": "shift",
"spec": {
"country": "country",
"state": {
"*": { // state array index
"stateName": "state[&1].stateName",
"location": "state[&1].location",
"cities": {
"*": { // city array index
"name": "state[&3].cities[&1].cityname",
"pop": "state[&3].cities[&1].citypopualtion"
}
}
}
}
}
}
]
【问题讨论】:
标签: json wildcard transformation shift jolt