I have the following json format string as below.
json_data_string = "{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"time_zone\":\"+09:00\",\"gte\":\"2023-01-24T00:00:00.000Z\",\"lt\":\"2023-01-25T00:00:00.000Z\"}}},{\"term\":{\"serviceid.keyword\":{\"value\":\"430011397\"}}}]}},\"aggs\":{\"by_day\":{\"auto_date_histogram\":{\"field\":\"@timestamp\",\"minimum_interval\":\"minute\"},\"aggs\":{\"agg-type\":{\"terms\":{\"field\":\"nxlogtype.keyword\",\"size\":1000},\"aggs\":{\"my-sub-agg-name\":{\"avg\":{\"field\":\"size\"}}}}}}}}"
In this field, there is gte field which is the starting time.
I would like to put this value by variable, not by the constant string as shown above.
For example, I want to generate many json format string by using the for-loop as below.
fmt = '%Y-%m-%d %H:%M:%S'
d1 = datetime.strptime('2010-01-01 00:00:00', fmt)
d2 = datetime.strptime('2010-01-02 00:00:00', fmt)
minutesDiff = (d2 - d1).days * 24 * 60
for n in range(minutesDiff):
print(json_data_string_variable.format(datetime.strptime(str(d1 + timedelta(minutes=n)),fmt)))
By using the iterative style, I think that I can generate the multiple json string but I don't have idea to insert variable format in the json_data_string. I have googled it and tried to use {} syntax in the json_data_string but it did not work.
How to achieve it?
Thanks.