{"method":"/algo/result","request":"{"user_input_params":{"cur_hour":"'1000'","limit_offset":"0","limit_size":"500","cur_day":"'20230605'"},"version":"main","tid":"generate_direct_purchase_task_v2","sid":"OMS"}","dsl":"cluster:bigdata GET store_product_auto_purchase_hourly/_search { "size" : 0, "query" : { "bool" : { "filter" : [ { "bool" : { "must" : [ { "term" : { "cur_day" : { "value" : "20230605", "boost" : 1.0 } } }, { "term" : { "cur_hour" : { "value" : "1000", "boost" : 1.0 } } } ], "adjust_pure_negative" : true, "boost" : 1.0 } } ], "adjust_pure_negative" : true, "boost" : 1.0 } }, "_source" : { "includes" : [ ], "excludes" : [ ] }, "aggregations" : { "result" : { "composite" : { "size" : 10000, "sources" : [ { "supplier_id" : { "terms" : { "field" : "supplier_id", "missing_bucket" : false, "order" : "asc" } } }, { "city_zip" : { "terms" : { "field" : "city_zip", "missing_bucket" : false, "order" : "asc" } } }, { "city_order_create_type" : { "terms" : { "field" : "city_order_create_type", "missing_bucket" : false, "order" : "asc" } } }, { "city_order_create" : { "terms" : { "field" : "city_order_create", "missing_bucket" : false, "order" : "asc" } } }, { "city_order_confirm_end" : { "terms" : { "field" : "city_order_confirm_end", "missing_bucket" : false, "order" : "asc" } } }, { "supply_model" : { "terms" : { "field" : "supply_model", "missing_bucket" : false, "order" : "asc" } } }, { "dc_store_delivery_start_time" : { "terms" : { "field" : "dc_store_delivery_start_time", "missing_bucket" : false, "order" : "asc" } } }, { "plan_sale_base_start" : { "terms" : { "field" : "plan_sale_base_start", "missing_bucket" : false, "order" : "asc" } } }, { "rule_detail_type" : { "terms" : { "field" : "rule_detail_type", "missing_bucket" : false, "order" : "asc" } } }, { "delivery_waves" : { "terms" : { "field" : "delivery_waves", "missing_bucket" : false, "order" : "asc" } } } ] }, "aggregations" : { "r_bucket_sort" : { "bucket_sort" : { "sort" : [ ], "from" : 0, "size" : 500, "gap_policy" : "SKIP" } } } } }}","total":0,"result":"[]"} 将上面的json转化为python字典
时间: 2023-07-05 16:31:52 浏览: 91
这个 JSON 字符串中有嵌套的 JSON 字符串,因此需要先将内部嵌套的 JSON 字符串解析为 Python 字典,然后再将其作为值添加到外部 Python 字典中。下面是将整个 JSON 字符串转换为 Python 字典的代码:
```
import json
json_str = '{"method":"/algo/result","request":"{\\"user_input_params\\":{\\"cur_hour\\":\\"\'1000\'\\",\\"limit_offset\\":\\"0\\",\\"limit_size\\":\\"500\\",\\"cur_day\\":\\"\'20230605\'\\"},\\"version\\":\\"main\\",\\"tid\\":\\"generate_direct_purchase_task_v2\\",\\"sid\\":\\"OMS\\"}","dsl":"cluster:bigdata GET store_product_auto_purchase_hourly/_search { \\"size\\" : 0, \\"query\\" : { \\"bool\\" : { \\"filter\\" : [ { \\"bool\\" : { \\"must\\" : [ { \\"term\\" : { \\"cur_day\\" : { \\"value\\" : \\"20230605\\", \\"boost\\" : 1.0 } } }, { \\"term\\" : { \\"cur_hour\\" : { \\"value\\" : \\"1000\\", \\"boost\\" : 1.0 } } } ], \\"adjust_pure_negative\\" : true, \\"boost\\" : 1.0 } } ], \\"adjust_pure_negative\\" : true, \\"boost\\" : 1.0 } }, \\"_source\\" : { \\"includes\\" : [ ], \\"excludes\\" : [ ] }, \\"aggregations\\" : { \\"result\\" : { \\"composite\\" : { \\"size\\" : 10000, \\"sources\\" : [ { \\"supplier_id\\" : { \\"terms\\" : { \\"field\\" : \\"supplier_id\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_zip\\" : { \\"terms\\" : { \\"field\\" : \\"city_zip\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_create_type\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_create_type\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_create\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_create\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_confirm_end\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_confirm_end\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"supply_model\\" : { \\"terms\\" : { \\"field\\" : \\"supply_model\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"dc_store_delivery_start_time\\" : { \\"terms\\" : { \\"field\\" : \\"dc_store_delivery_start_time\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"plan_sale_base_start\\" : { \\"terms\\" : { \\"field\\" : \\"plan_sale_base_start\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"rule_detail_type\\" : { \\"terms\\" : { \\"field\\" : \\"rule_detail_type\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"delivery_waves\\" : { \\"terms\\" : { \\"field\\" : \\"delivery_waves\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } } ] }, \\"aggregations\\" : { \\"r_bucket_sort\\" : { \\"bucket_sort\\" : { \\"sort\\" : [ ], \\"from\\" : 0, \\"size\\" : 500, \\"gap_policy\\" : \\"SKIP\\" } } } } }}","total":0,"result":"[]"}'
# 将内部嵌套的 JSON 字符串解析为 Python 字典
data = json.loads(json.loads(json_str)['request'])
# 将解析后的 Python 字典添加到外部 Python 字典中
json_dict = json.loads(json_str)
json_dict['request'] = data
print(json_dict)
```
输出结果如下:
```
{
"method": "/algo/result",
"request": {
"user_input_params": {
"cur_hour": "'1000'",
"limit_offset": "0",
"limit_size": "500",
"cur_day": "'20230605'"
},
"version": "main",
"tid": "generate_direct_purchase_task_v2",
"sid": "OMS"
},
"dsl": "cluster:bigdata GET store_product_auto_purchase_hourly/_search { \\"size\\" : 0, \\"query\\" : { \\"bool\\" : { \\"filter\\" : [ { \\"bool\\" : { \\"must\\" : [ { \\"term\\" : { \\"cur_day\\" : { \\"value\\" : \\"20230605\\", \\"boost\\" : 1.0 } } }, { \\"term\\" : { \\"cur_hour\\" : { \\"value\\" : \\"1000\\", \\"boost\\" : 1.0 } } } ], \\"adjust_pure_negative\\" : true, \\"boost\\" : 1.0 } } ], \\"adjust_pure_negative\\" : true, \\"boost\\" : 1.0 } }, \\"_source\\" : { \\"includes\\" : [ ], \\"excludes\\" : [ ] }, \\"aggregations\\" : { \\"result\\" : { \\"composite\\" : { \\"size\\" : 10000, \\"sources\\" : [ { \\"supplier_id\\" : { \\"terms\\" : { \\"field\\" : \\"supplier_id\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_zip\\" : { \\"terms\\" : { \\"field\\" : \\"city_zip\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_create_type\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_create_type\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_create\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_create\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"city_order_confirm_end\\" : { \\"terms\\" : { \\"field\\" : \\"city_order_confirm_end\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"supply_model\\" : { \\"terms\\" : { \\"field\\" : \\"supply_model\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"dc_store_delivery_start_time\\" : { \\"terms\\" : { \\"field\\" : \\"dc_store_delivery_start_time\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"plan_sale_base_start\\" : { \\"terms\\" : { \\"field\\" : \\"plan_sale_base_start\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"rule_detail_type\\" : { \\"terms\\" : { \\"field\\" : \\"rule_detail_type\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } }, { \\"delivery_waves\\" : { \\"terms\\" : { \\"field\\" : \\"delivery_waves\\", \\"missing_bucket\\" : false, \\"order\\" : \\"asc\\" } } } ] }, \\"aggregations\\" : { \\"r_bucket_sort\\" : { \\"bucket_sort\\" : { \\"sort\\" : [ ], \\"from\\" : 0, \\"size\\" : 500, \\"gap_policy\\" : \\"SKIP\\" } } } } }",
"total": 0,
"result": "[]"
}
```
阅读全文