使用 jolt 从数组中删除 null
Remove null from array using jolt
我在使用 jolt 从数组中删除空值时遇到一些问题,如下所述:
输入
{
"userId": "1",
"age": "20",
"firstName": "firstname1",
"lastname": "lastname1",
"zipCode": "zipcode1",
"street": "street1",
"city": "city1",
"country": "country",
"gender": "gender1",
"grade": "grade1",
"birthday": "birthday1"
}
震动规格
[
{
"operation": "shift",
"spec": {
"userId": "ID",
"age": "age",
"firstName": "firstName",
"lastname": "lastname",
"gender": "gender",
"grade": "grade",
"birthday": "birthday",
"street|city|zipCode|country": {
"$": "address[#2].code",
"@": "address[#2].value"
}
}
}
]
输出
{
"ID": "1",
"age": "20",
"firstName": "firstname1",
"lastname": "lastname1",
"gender": "gender1",
"grade": "grade1",
"birthday": "birthday1",
"address": [ null, null, null, null, null, null, null,
{
"code": "street",
"value": "street1"
},
{
"code": "city",
"value": "city1"
},
{
"code": "zipCode",
"value": "zipcode1"
},
{
"code": "country",
"value": "country"
}
]
}
我得到了@Barbaros 建议的一些解决方案,感谢他在 link 中的描述
但仍在苦苦挣扎,如有任何帮助,我们将不胜感激。
您可以在第一步中使用诸如 adr_
之类的文字作为键值对的前缀,然后在最后一步中使用以区分将由 [=12= 符号化的其余属性]对如
[
{
"operation": "shift",
"spec": {
"userId": "ID",
"*": "&",
"street|city|zipCode|country": {
"$": "adr_&.code",
"@": "adr_&.value"
}
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"adr_*": "address[]"
}
}
]
这里只有 "userId": "ID"
单独写,以便根据需要重命名。
我在使用 jolt 从数组中删除空值时遇到一些问题,如下所述:
输入
{
"userId": "1",
"age": "20",
"firstName": "firstname1",
"lastname": "lastname1",
"zipCode": "zipcode1",
"street": "street1",
"city": "city1",
"country": "country",
"gender": "gender1",
"grade": "grade1",
"birthday": "birthday1"
}
震动规格
[
{
"operation": "shift",
"spec": {
"userId": "ID",
"age": "age",
"firstName": "firstName",
"lastname": "lastname",
"gender": "gender",
"grade": "grade",
"birthday": "birthday",
"street|city|zipCode|country": {
"$": "address[#2].code",
"@": "address[#2].value"
}
}
}
]
输出
{
"ID": "1",
"age": "20",
"firstName": "firstname1",
"lastname": "lastname1",
"gender": "gender1",
"grade": "grade1",
"birthday": "birthday1",
"address": [ null, null, null, null, null, null, null,
{
"code": "street",
"value": "street1"
},
{
"code": "city",
"value": "city1"
},
{
"code": "zipCode",
"value": "zipcode1"
},
{
"code": "country",
"value": "country"
}
]
}
我得到了@Barbaros 建议的一些解决方案,感谢他在 link 中的描述
但仍在苦苦挣扎,如有任何帮助,我们将不胜感激。
您可以在第一步中使用诸如 adr_
之类的文字作为键值对的前缀,然后在最后一步中使用以区分将由 [=12= 符号化的其余属性]对如
[
{
"operation": "shift",
"spec": {
"userId": "ID",
"*": "&",
"street|city|zipCode|country": {
"$": "adr_&.code",
"@": "adr_&.value"
}
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"adr_*": "address[]"
}
}
]
这里只有 "userId": "ID"
单独写,以便根据需要重命名。