"cassandra": {
"host": "1.1.1.1",
"portNo": "9042",
"keyspace": "good"
},
"postgres": {
"host": "2.2.2.2",
"portNo": "5432",
"database": "dude",
"username": "root",
"password": "something"
}
这是json文件的一部分。我需要使用脚本编辑具有两个不同IP的主机部分。任何人都有任何想法
答案 0 :(得分:2)
使用{}
正确使用json(上面的数据被jq
包围):
$ jq '.|.cassandra.host="foo"' file.json
{
"cassandra": {
"host": "foo",
"portNo": "9042",
"keyspace": "good"
},
"postgres": {
"host": "2.2.2.2",
"portNo": "5432",
"database": "dude",
"username": "root",
"password": "something"
}
}
答案 1 :(得分:1)
您可以使用Json python包
import json
my_bytes_value = response.content
my_json = my_bytes_value.decode('utf8')
jsonResponse = json.loads(my_json)
resultCount = jsonResponse["cassandra"]