jolt - 坚持简单的颠簸转换
问题描述
所以我从谷歌地图 API 中检索了这个 json,我只想得到经度和纬度。我希望使用 jolt 模板来提取我需要的信息。
{
"results": [
{
"address_components": [
{
"long_name": "1115",
"short_name": "1115",
"types": [
"street_number"
]
},
{
"long_name": "West Idaho Avenue",
"short_name": "W Idaho Ave",
"types": [
"route"
]
},
{
"long_name": "Ontario",
"short_name": "Ontario",
"types": [
"locality",
"political"
]
},
{
"long_name": "Malheur County",
"short_name": "Malheur County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Oregon",
"short_name": "OR",
"types": [
"administrative_area_level_1",
"political"
]
},
{`enter code here`
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "97914",
"short_name": "97914",
"types": [
"postal_code"
]
},
{
"long_name": "2146",
"short_name": "2146",
"types": [
"postal_code_suffix"
]
}
],
"formatted_address": "1115 W Idaho Ave, Ontario, OR 97914, USA",
"geometry": {
"location": {
"lat": 44.0294445,
"lng": -116.9776502
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 44.03079348029149,
"lng": -116.9763012197085
},
"southwest": {
"lat": 44.02809551970849,
"lng": -116.9789991802915
}
}
},
"partial_match": true,
"place_id": "ChIJP3C3Z6uPr1QRUDkcSIXzx5g",
"types": [
"establishment",
"point_of_interest",
"school"
]
}
],
"status": "OK"
}
所以这是我正在使用的颠簸规范:
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"geometry": {
"location": {
"lat": "employees[&1].firstName",
"lng": "employees[&1].lastName"
}
}
}
}
}
}
]
我想检索一个看起来像这样的 json:
{
"data" : [
{
"lng": "-116.9763012197085",
"lat": "44.0294445"
} ]
}
但我一直为空......任何帮助将不胜感激谢谢
解决方案
您原来的规格不起作用,因为"lat": "employees[&1].firstName"
应该是"lat": "employees[&3].firstName"
.
在这种情况下&1
,评估为“位置”一词。 &3
让你在树上找到输入results
数组的索引,这就是我认为你的意思。
Shift 在进行转换时维护一个堆栈,&
通配符允许您从堆栈/树中获取先前匹配的值。
从"lat"
规范中的 where 开始,堆栈 0,1,2,3 向上 4 级,以到达结果数组的索引,该索引与*
.
规格
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"geometry": {
"location": {
"lat": "data[&3].lat",
"lng": "data[&3].lng"
}
}
}
}
}
}
]
推荐阅读
- python - 检测帧并分割为 78x42 区域并给出每个区域的平均颜色
- python - 我可以使用 argparse 帮助字符串来描述我的脚本的返回值吗?
- python - 当我在机器学习中使用不同的数据集测试模型时,为什么结果不准确?
- javascript - Drone CI 找不到 100% 肯定存在的 Node 模块
- android - 颤振,如何将图像网络设置为壁纸2021
- sparql - 如何使用 SPARQL 查询本地 ttl 文件?
- extjs - ExtJS 7 如何在右键单击时选择网格行
- reactjs - 将多张图片上传到 firebase,然后将图片 url 保存到 firestore
- html - 我的 css 链接出现问题“标签开始未关闭”
- java - colorPrimary 覆盖按钮样式