【发布时间】:2017-09-06 11:15:23
【问题描述】:
鉴于以下剧本从一些随机的webservice 中获取一些数据:
---
- name: sorting json
hosts: localhost
tasks:
- name:
uri:
url: http://jsonplaceholder.typicode.com/users
method: GET
return_content: yes
register: result
ignore_errors: yes
- debug: msg="{{result.content}}"
Ansible 正在重新排序 json 输出:
输出(数组的第一个元素,重新排序):
{
"address": {
"city": "Gwenborough",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
},
"street": "Kulas Light",
"suite": "Apt. 556",
"zipcode": "92998-3874"
},
"company": {
"bs": "harness real-time e-markets",
"catchPhrase": "Multi-layered client-server neural-net",
"name": "Romaguera-Crona"
},
"email": "Sincere@april.biz",
"id": 1,
"name": "Leanne Graham",
"phone": "1-770-736-8031 x56442",
"username": "Bret",
"website": "hildegard.org"
},
而原始数据是:
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
如何获得一个没有重新排序的漂亮、格式化的 JSON? (我看过this question,如果可以的话还是不错的)
【问题讨论】: