title: How in groovy (java) automatically find out the json field type and return values from json, replacing null with empty space?
body: <p>The question is still relevant!</p>
  <p>In my task, json comes to my input, which I do not know in advance. I need to collect all json field types into &quot;types&quot; and return all values ​​using <code>reader.outputLines</code>. Now the list of json field types is formed like this:
  <code>def types = list.find (). Values ​​() *. GetClass () *. SimpleName</code>
  But I am faced with a problem when the same field in the first json block is null, and in the second the integer and the type is defined as null, and not as Integer.</p>
  <ol>
  <li>How to make sure that the type is determined by going through all the json blocks for each field, and not making an output based on the first block, and if everything is null or &quot;&quot; (empty), assign the default String?</li>
  <li>When returning values ​​from json using <code>reader.outputLines</code>, replace null with &quot;&quot; (empty)?</li>
  </ol>
  <pre><code>import groovy.json.JsonSlurper
  import ru.itrpro.xm.plugins.groovy.ResultSetReader;
  
  class XM_PARSE_XLS {
  
      def execute(ResultSetReader reader, String pfile) {
  
          def jsonSlurper = new JsonSlurper()
          def list = jsonSlurper.parseText pfile
  
          List names = list.inject( new LinkedHashSet&lt;&gt;() ){ res, map -&gt;
              res.addAll map.keySet()
              res
          }.toList()
          def types = list.find().values()*.getClass()*.simpleName
  
          //formation of the dataset header
          reader.outputLinesSetHeaders(names,types);
  
          list.each{ e -&gt;
              reader.outputLines names.collect{ e[ it ] }
              //println names.collect{ e[ it ] }
          }
  
          //closing dataset
          reader.outputLinesEnd();
          return null;
  
      }
      static void main(String... args) {
          String pfile =  &quot;&quot;&quot;
  [{&quot;AUTO&quot;:&quot;bmw&quot;,
    &quot;HOME&quot;:null,
    &quot;JOB&quot;:&quot;&quot;},
    
    {&quot;AUTO&quot;:&quot;audi&quot;,
    &quot;HOME&quot;:135,
    &quot;JOB&quot;:null},
    
    {&quot;AUTO&quot;:&quot;opel1&quot;,
    &quot;HOME&quot;:10,
    &quot;JOB&quot;:null}]
  &quot;&quot;&quot;
          def SSC = new XM_PARSE_XLS()
          def res = SSC.execute(new ResultSetReader(), pfile)
      }
  }
  </code></pre>