我有一个专门用于.json文件的数据库。 例如,在某个时候,它会这样做
with open(document_key) as file_to_get:
content = json.load(file_to_get)
response = self._create_store_response(status_code=StatusCode.OK, content=content)
现在我遇到了一个用例,其中我的file_to_get是一个rego文件。下面是一个示例:
multiple_redundancy {
value := 1
count(infrastructure_targets[0]) >= value
}
我想做的仍然是通过将其处理为与json兼容并且可以轻松转换回去的格式来将其作为json文件加载。
在上面的代码中,它将变为:
file_to_get_as_json = to_json(file_to_get) # this should do nothing if the
# file is already json
但是,我不确定如何最好地解决它。将文件转换为字符串并将其添加为键?但是json格式要求使它变得不平凡,因此,我正在寻找一些反馈。