title: Dot notation to Json in python
body: <p>I receive data from the Loggly service in dot notation, but to put data back in, it must be in JSON.</p>
  
  <p>Hence, I need to convert:</p>
  
  <pre><code>{'json.message.status.time':50, 'json.message.code.response':80, 'json.time':100}
  </code></pre>
  
  <p>Into:</p>
  
  <pre><code>{'message': {'code': {'response': 80}, 'status': {'time': 50}}, 'time': 100}
  </code></pre>
  
  <p>I have put together a function to do so, but I wonder if there is a more direct and simpler way to accomplish the same result.</p>
  
  <pre><code>def dot_to_json(a):
  
      # Create root for JSON tree structure
      resp = {}
  
      for k,v in a.items():
          # eliminate json. (if metric comes from another type, it will keep its root)
          k = re.sub(r'\bjson.\b','',k)
          if '.' in k:
              # Field has a dot
              r = resp
              s = ''
              k2 =  k.split('.')
              l = len(k2)
              count = 0
              t = {}
              for f in k2:
                  count += 1
                  if f not in resp.keys():
                      r[f]={}
                  r = r[f]
                  if count &lt; l:
                      s += "['" + f + "']"
                  else:
                      s = "resp%s" % s
                      t = eval(s)
                      # Assign value to the last branch
                      t[f] = v
          else:
              r2 = resp
              if k not in resp.keys():
                  r2[k] = {}
              r2[k] = v
      return resp
  </code></pre>