'python dynamically append keys and values to a JSON [closed]

Im trying to generate a json file with dynamic values.

sample format

  {
  "dynamic_key1": [
  
              { "Name1":"dynamic_value1" ,
              "Name2":"dynamic_value2" }],
   
  "dynamic_key2": [
  
              { "Name3":"dynamic_value3" ,
              "Name4":"dynamic_value4" }]
  
   } 

How to generate a json file based up on the sample format

input data should be read from a dataframe like followingenter image description here:



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source