json - 颠簸转换 - 小写所有键?
问题描述
我有以下 JSON:-
{
"ROWNUM": "328938",
"SOURCE_NAME": "I2323",
"ID": "333333",
"FIRST_NAME": "A121221",
"KNOWN_AS": "G1223321",
"LAST_NAME": "sadsadsd",
"PLACE_OF_BIRTH": "Indsadsadsaddsaia",
"DATE_OF_BIRTH": "sadsaddsa",
"UPRN": "sadsadsad",
"POST_CODE": "asdsadsda",
"POST_TOWN": "GLASGOW",
"ESTIMATED_DOB": "N",
"LAST_UPDATED": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"aliases": [
{
"_id": {
"timestamp": 1550152767,
"machineIdentifier": 6505561,
"processIdentifier": 59,
"counter": 2775622,
"time": 1550152767000,
"timeSecond": 1550152767,
"date": 1550152767000
},
"ROWNUM": "328938",
"SOURCE_NAME": "I2323",
"ID": "333333",
"FIRST_NAME": "A121221",
"KNOWN_AS": "G1223321",
"LAST_NAME": "sadsadsd",
"PLACE_OF_BIRTH": "Indsadsadsaddsaia",
"DATE_OF_BIRTH": "sadsaddsa",
"UPRN": "sadsadsad",
"POST_CODE": "asdsadsda",
"POST_TOWN": "GLASGOW",
"ESTIMATED_DOB": "N",
"LAST_UPDATED": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"score": "0.9997580647468567"
},
{
"_id": {
"timestamp": 1550152767,
"machineIdentifier": 6505561,
"processIdentifier": 59,
"counter": 2775622,
"time": 1550152767000,
"timeSecond": 1550152767,
"date": 1550152767000
},
"ROWNUM": "328938",
"SOURCE_NAME": "I2323",
"ID": "333333",
"FIRST_NAME": "A121221",
"KNOWN_AS": "G1223321",
"LAST_NAME": "sadsadsd",
"PLACE_OF_BIRTH": "Whatever",
"DATE_OF_BIRTH": "sadsaddsa",
"UPRN": "sadsadsad",
"POST_CODE": "asdsadsda",
"POST_TOWN": "PAISLEY",
"ESTIMATED_DOB": "N",
"LAST_UPDATED": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"score": "0.9997580647468567"
}
]
}
是否有一个 jolt 规范可以小写每个键,包括嵌套对象中的键?(在这种情况下是什么aliases
)。
以下适用于顶级键,但不适用于嵌套键:
[
{
// unwrap the keys and values into literal
// "key" : "A", "value" : "b"
"operation": "shift",
"spec": {
"*": {
"$": "&1.key",
"@": "&1.value"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
// Now that the origional key
// is on the "right hand side"
// lowercase it
"key": "=toLower"
}
}
},
{
// pivot back, the now lowercased keys
"operation": "shift",
"spec": {
"*": {
"value": "@(1,key)"
}
}
}
]
谢谢!
解决方案
这会产生扩展现有转换的所需结果:
[
{
// unwrap the keys and values into literal
// "key" : "A", "value" : "b"
"operation": "shift",
"spec": {
"*": {
"$": "&1.key",
"@": "&1.value"
},
//do the same for everything in aliases
//&3 = aliases
//&2 = array position
//&1 = position of kvp
"aliases": {
"*": {
"*": {
"$": "&3.&2.&1.key",
"@": "&3.&2.&1.value"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
// Now that the origional key
// is on the "right hand side"
// lowercase it
"key": "=toLower"
},
"aliases": {
"*": {
"*": {
// Now that the origional key
// is on the "right hand side"
// lowercase it
"key": "=toLower"
}
}
}
}
},
{
// pivot back, the now lowercased keys
"operation": "shift",
"spec": {
"*": {
"value": "@(1,key)"
},
"aliases": {
"*": {
"*": {
//&3 = aliases
//&2 = array postion
//@(1,key) values from "key"
"value": "&3.[&2].@(1,key)"
}
}
}
}
}
]
产生以下内容:
{
"rownum": "328938",
"source_name": "I2323",
"id": "333333",
"first_name": "A121221",
"known_as": "G1223321",
"last_name": "sadsadsd",
"place_of_birth": "Indsadsadsaddsaia",
"date_of_birth": "sadsaddsa",
"uprn": "sadsadsad",
"post_code": "asdsadsda",
"post_town": "GLASGOW",
"estimated_dob": "N",
"last_updated": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"aliases": [
{
"_id": {
"timestamp": 1550152767,
"machineIdentifier": 6505561,
"processIdentifier": 59,
"counter": 2775622,
"time": 1550152767000,
"timeSecond": 1550152767,
"date": 1550152767000
},
"rownum": "328938",
"source_name": "I2323",
"id": "333333",
"first_name": "A121221",
"known_as": "G1223321",
"last_name": "sadsadsd",
"place_of_birth": "Indsadsadsaddsaia",
"date_of_birth": "sadsaddsa",
"uprn": "sadsadsad",
"post_code": "asdsadsda",
"post_town": "GLASGOW",
"estimated_dob": "N",
"last_updated": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"score": "0.9997580647468567"
},
{
"_id": {
"timestamp": 1550152767,
"machineIdentifier": 6505561,
"processIdentifier": 59,
"counter": 2775622,
"time": 1550152767000,
"timeSecond": 1550152767,
"date": 1550152767000
},
"rownum": "328938",
"source_name": "I2323",
"id": "333333",
"first_name": "A121221",
"known_as": "G1223321",
"last_name": "sadsadsd",
"place_of_birth": "Whatever",
"date_of_birth": "sadsaddsa",
"uprn": "sadsadsad",
"post_code": "asdsadsda",
"post_town": "PAISLEY",
"estimated_dob": "N",
"last_updated": "2019-02-11T13:57:05.264Z",
"cluster_id": 3020,
"score": "0.9997580647468567"
}
]
}
推荐阅读
- javascript - 如果 attr() 中有重复属性,那么它是否总是在 jquery 中应用最后一个重复属性?
- php - 将 HTML 编码文本与 PHP 中的纯文本进行比较
- javascript - 意外的未定义结果
- php - 如何从给定的公斤和克计算撬数
- azure - 在 azure 中重新启动应用服务后出现 500.30 错误
- javascript - 尝试从 chrome 扩展中的 URL 播放音频时出错
- c++ - 有没有办法在编译时从 initializer_list 构造?
- apache-spark - Cassandra 上的 great_expectations 数据验证
- woocommerce - 为什么 WooCommerce 可变产品价格显示两次?
- python - 如何在带有 if 的辅助函数中使用 isdigit() 方法