我是新来的震动,只是不能理解有关列表的语法。我有以下JSON:
{
"Country": [
{
"Name": "Angola",
"AnimalNames.AnimalName": [
"Aspidelaps lubricus",
"Atheris squamigera",
"Atractaspis bibronii"
]
},
{
"Name": "Argentina",
"AnimalNames.AnimalName": [
"Apis mellifera scutellata",
"Bothrops alternatus",
"Bothrops ammodytoides"
]
}
]
}期望产出:
[
{
"country_name":"Angola",
"species":"Aspidelaps lubricus"
},
{
"country_name":"Angola",
"species":"Atheris squamigera"
},
{
"country_name":"Angola",
"species":"Atractaspis bibronii"
},
{
"country_name":"Argentina",
"species":"Apis mellifera scutellata"
},
{
"country_name":"Argentina",
"species":"Bothrops alternatus"
},
{
"country_name":"Argentina",
"species":"Bothrops ammodytoides"
}
]我所有的尝试都给了我一份所有国家的名单和所有物种的名单。
提前感谢
发布于 2022-10-13 12:57:00
可以使用以下shift转换规范,如所解释的方式所示
[
{
"operation": "shift",
"spec": {
"Country": {
"*": { // level of the indexes of the "Country" array
"AnimalNames*": { // represents the key-value pair(attribute,object or array) starting with animal
"*": { // the indexes of the current array(if it was an object this level wouldn't exist)
"@(2,Name)": "@(3,Name)[&1].country_name", // group by the countries and their respective sub-indexes within the arrays where "@(2,Name)" represents going two levels up the tree and grabbing the value of "Name" attribute
"@": "@(3,Name)[&1].species" // go three levels up the tree by traversing : and double { in order to reach the level of the Country Name while indexing with "AnimalNames.AnimalName" arrays by [&1] to go one level up as keeping array style by square brackets and "species" is a fixed tag name
}
}
}
}
}
},
{
// get rid of the array tags
"operation": "shift",
"spec": {
"*": ""
}
}
]https://stackoverflow.com/questions/74055800
复制相似问题