title: How to parser JSON and add some custom strings?
body: <p>I have a JSON which come from spark:</p>
  
  <pre><code>val df = spark.read.parquet("hdfs://xxx-namespace/20190311")
  val jsonStr = df.schema.json
  </code></pre>
  
  <p><code>jsonStr</code> is like this:</p>
  
  <pre><code>{
      "type":"struct",
      "fields":[
          {
              "name":"alm_dm_list",
              "type":{
                  "type":"array",
                  "elementType":"integer",
                  "containsNull":true
              },
              "nullable":true,
              "metadata":{
  
              }
          },
          {
              "name":"data_batt_sc_volt_lowest",
              "type":"double",
              "nullable":true,
              "metadata":{
  
              }
          },
          {
              "name":"veh_dcdcst",
              "type":"integer",
              "nullable":true,
              "metadata":{
  
              }
          },
          {
              "name":"esd_temp_data",
              "type":{
                  "type":"array",
                  "elementType":{
                      "type":"struct",
                      "fields":[
                          {
                              "name":"esd_temp_probe_cnt",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_temp_probe_list",
                              "type":{
                                  "type":"array",
                                  "elementType":"integer",
                                  "containsNull":true
                              },
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_temp_subsys_seq",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          }
                      ]
                  },
                  "containsNull":true
              },
              "nullable":true,
              "metadata":{
  
              }
          },
          {
              "name":"esd_volt_data",
              "type":{
                  "type":"array",
                  "elementType":{
                      "type":"struct",
                      "fields":[
                          {
                              "name":"esd_curr",
                              "type":"double",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_frame_sc_cnt",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_frame_sc_list",
                              "type":{
                                  "type":"array",
                                  "elementType":"double",
                                  "containsNull":true
                              },
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_frame_start",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_sc_cnt",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_volt",
                              "type":"double",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"esd_volt_subsys_seq",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          }
                      ]
                  },
                  "containsNull":true
              },
              "nullable":true,
              "metadata":{
  
              }
          },
          {
              "name":"dm_data",
              "type":{
                  "type":"array",
                  "elementType":{
                      "type":"struct",
                      "fields":[
                          {
                              "name":"dm_ctl_dc_curr",
                              "type":"double",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_ctl_temp",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_ctl_volt",
                              "type":"double",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_seq",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_spd",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_st",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_temp",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          },
                          {
                              "name":"dm_torq",
                              "type":"integer",
                              "nullable":true,
                              "metadata":{
  
                              }
                          }
                      ]
                  },
                  "containsNull":true
              },
              "nullable":true,
              "metadata":{
  
              }
          }]
  }       
  </code></pre>
  
  <p>I want to get a scheme based on the JSON string, so i need to parse it and get a struct like this:</p>
  
  <pre><code>  val schema = new StructType()
      .add("alm_dm_list", ArrayType(IntegerType, true), true)
      .add("data_batt_sc_volt_lowest", DoubleType, true)
      .add("veh_dcdcst", IntegerType, true)
      .add("esd_temp_data", ArrayType(new StructType()
        .add("esd_temp_probe_cnt", IntegerType, true)
        .add("esd_temp_probe_list", ArrayType(IntegerType, true), true)
        .add("esd_temp_subsys_seq", IntegerType, true)
      ), true)
      .add("esd_volt_data", ArrayType(new StructType()
        .add("esd_curr", DoubleType, true)
        .add("esd_frame_sc_cnt", IntegerType, true)
        .add("esd_frame_sc_list", ArrayType(DoubleType, true), true)
        .add("esd_frame_start", IntegerType, true)
        .add("esd_sc_cnt", IntegerType, true)
        .add("esd_volt", DoubleType, true)
        .add("esd_volt_subsys_seq", IntegerType, true)
      ), true)
      .add("dm_data", ArrayType(new StructType()
        .add("dm_ctl_dc_curr", DoubleType, true)
        .add("dm_ctl_temp", IntegerType, true)
        .add("dm_ctl_volt", DoubleType, true)
        .add("dm_seq", IntegerType, true)
        .add("dm_spd", IntegerType, true)
        .add("dm_st", IntegerType, true)
        .add("dm_temp", IntegerType, true)
        .add("dm_torq", IntegerType, true)
      ), true)
  </code></pre>
  
  <p><a href="https://github.com/jonathanstowe/JSON-Infer" rel="noreferrer">JSON::Infer</a> maybe helpful, but there are nested structures in my JSON, which is complex for me, any suggestions will help.</p>