title: How to split JSON fields containing '_' into sub-objects?
body: <p>I have the following JSON object, in which I need to post-process some labels:</p>
  <pre><code>{
   'id': '123',
   'type': 'A',
   'fields': 
    {
        'device_safety': 
        {
           'cost': 0.237,
           'total': 22
        },
        'device_unit_replacement': 
        {
           'cost': 0.262,
           'total': 7
        },
        'software_generalinfo': 
        {
           'cost': 3.6,
           'total': 10
        }
    }
  }
  </code></pre>
  <p>I need to split the names of labels by <code>_</code> to get the following hierarchy:</p>
  <pre><code>{
   'id': '123',
   'type': 'A',
   'fields': 
    {
        'device': 
        {
           'safety': 
           {
               'cost': 0.237,
               'total': 22
           },
           'unit':
           {
               'replacement':
               {
                    'cost': 0.262,
                    'total': 7
               }  
           }
        },
        'software': 
        {
           'generalinfo':
           {
              'cost': 3.6,
              'total': 10
           }
        }
    }
  }
  </code></pre>
  <p>This is my current version, but I got stuck and not sure how to deal with the hierarchy of fields:</p>
  <pre><code>import json
  
  json_object = json.load(raw_json)
  
  newjson = {}
  for x, y in json_object['fields'].items():
      hierarchy = y.split(&quot;_&quot;)
      if len(hierarchy) &gt; 1:
           for k in hierarchy:
                newjson[k] = ????
  
  newjson = json.dumps(newjson, indent = 4)
  </code></pre>