-3

I have a nested dicts. Here is my dict:

org_query = {"query": {"bool": {"must": [],"must_not": []}}}

I want to update another dict inside the nested dict. Here's the dict i want to add:

query_form =  { "match_phrase": { "name": "steve" }}

Required Output:

org_query = {"query": {"bool": {"must": [{ "match_phrase": { "name": "steve" }],"must_not": []}}}

I found this Update value of a nested dictionary of varying depth but it updates the value. In my case, i want to update the entire dict to the list in the key of the nested dict. How to make it possible.

Georgy
  • 12,464
  • 7
  • 65
  • 73

1 Answers1

1

In your case, that would be:

org_query["query"]["bool"]["must"].append(query_form)

More here: https://www.w3schools.com/python/python_dictionaries.asp

olinox14
  • 6,177
  • 2
  • 22
  • 39