1
{ "publicationSystem": "xyz",
       "deliveryMethod": "Queued",
       "recipients": [
      {
         "identifiers": [
            {
               "type": "CustomerId",
               "value": "123456783"
            }
         ]
      }
   ],
   "templateId": "123453",
   "templateFields": [
      {
         "id": "fuhu",
         "value": "Jojo"
      }
   ]
}

I'm using pydantic but still whenever i'm passing the json i get the error
Error: Unprocessable Entity

def extract_values(dct, lst=[], keys=[]):
    jumbo={}
    if not isinstance(dct, (list, dict)):
        lst.append(('_'.join(keys), dct))
    elif isinstance(dct, list):
        for i in dct:
            extract_values(i, lst, keys)
    elif isinstance(dct, dict):
        for k, v in dct.items():
            # print(k)

            keys.append(k)
            extract_values(v, lst, keys)
            keys.remove(k)
            # print(lst)
    for i in lst:
        jst = []
        i = list(i)
        jst = i[0].split("_")
        jumbo[jst[-1]] = i[1]
    return jumbo

this is the function i'm using to get the key value pairs of my json file but its showing error while taking input of the nested json string

Chris
  • 18,724
  • 6
  • 46
  • 80
  • More specifically, please have a look at [this answer](https://stackoverflow.com/a/70636163) – Chris Apr 08 '23 at 17:21

0 Answers0