Json Dumps仅选择检测到的键:true

时间:2019-04-04 06:52:38

标签: python json

我需要一些有关Json序列化的帮助。我只需要打印已检测到的密钥:true。

2 个答案:

答案 0 :(得分:0)

您可以简单地遍历json对象并在检测到== true时进行过滤。

例如:

import json

# This is your json data
input_json = """
[
  {
   ...
  }
]"""

# Load your json data and transform it to python objects
your_input_dict = json.loads(input_json)

# Filter the input dictionary
output = []
for x in your_input_dict:
  output = [obj for obj in x if x[obj]['detected'] == True]

print(output)

答案 1 :(得分:0)

您可以使用过滤器功能。

例如json是

example_json = [
   {
      "detected": True
   },
   {
      "detected": False
   }
]

list(filter(lambda x: (x["detected"] == True), example_json))
相关问题