当前位置: 首页 > 工具软件 > Jason > 使用案例 >

jason格式生成

拓拔坚
2023-12-01

想要生成如下格式jason文件:
{
  "query": {
    "bool": {
      "should": [
        {"term": {
          "staticUrl.keyword": "/text2video/videos/sanguo-jilu/sanguo-01/0.mp4"
        }}, 
        {"term": {
          "staticUrl.keyword": "/text2video/videos/sanguo-jilu/sanguo-01/1.mp4"
        }}
      ]
    }
  }
}

 

python代码:

import json
 

article = {'query': {'bool':{ 'should': []}}}

with open("flist2.video")  as f:
    for l in f.readlines():
        l=l.replace('\n', '')
        item={"term": {"staticUrl.keyword": "/text2video/videos/sanguo-jilu/"+l}}
        article['query']['bool']['should'].append(item)
 
data = json.dumps(article, ensure_ascii=False,sort_keys=True, indent=4, separators=(',', ':'))
print(data)

 

 类似资料: