title: How to convert json key as attribute in java
body: <p>I'm very new working java with json. Couldn't find relevant solutions. That's why posting this question. I have json with property name as value in it. How to convert this property name as attribute and restructured in array. Any help would be much appreciated.</p>
  <p>Following is my json file:</p>
  <p><em><strong>INPUT JSON:</strong></em></p>
  <pre><code>{
      &quot;payload&quot;: {
          &quot;giata&quot;: {
              &quot;435185&quot;: [
                  &quot;2019-11-27T14:34:32.368197Z&quot;
              ]
          },
          &quot;dod1&quot;: {
              &quot;A0947863&quot;: [
                  &quot;2019-11-27T14:34:32.368197Z&quot;
              ]
          },
          &quot;gr&quot;: {
              &quot;A0947863&quot;: [
                  &quot;2019-11-27T14:34:32.368197Z&quot;,
                  &quot;2021-04-27T06:13:12.841968Z&quot;,
                  &quot;2021-04-27T06:13:21.640612Z&quot;,
                  &quot;2021-04-27T06:13:28.439001Z&quot;,
                  &quot;2021-04-27T06:13:43.487103Z&quot;,
                  &quot;2021-04-27T06:13:49.770269Z&quot;
              ]
          }
      }
  }
  </code></pre>
  <p><em><strong>Expected JSON :</strong></em></p>
  <pre><code>{
      &quot;payload&quot;: {
          &quot;sources&quot;: [
              {
                  &quot;source&quot;: &quot;giata&quot;,
                  &quot;code&quot;: &quot;435185&quot;,
                  &quot;version&quot;: [
                      &quot;2019-11-27T14:34:32.368197Z&quot;
                  ]
              },
              {
                  &quot;source&quot;: &quot;dod1&quot;,
                  &quot;code&quot;: &quot;A0947863&quot;,
                  &quot;version&quot;: [
                      &quot;2019-11-27T14:34:32.368197Z&quot;
                  ]
              },
              {
                  &quot;source&quot;: &quot;gr&quot;,
                  &quot;code&quot;: &quot;A0947863&quot;,
                  &quot;version&quot;: [
                      &quot;2019-11-27T14:34:32.368197Z&quot;,
                      &quot;2021-04-27T06:13:12.841968Z&quot;,
                      &quot;2021-04-27T06:13:21.640612Z&quot;,
                      &quot;2021-04-27T06:13:28.439001Z&quot;,
                      &quot;2021-04-27T06:13:43.487103Z&quot;,
                      &quot;2021-04-27T06:13:49.770269Z&quot;
                  ]
              }
          ]
      }
  }
  </code></pre>
  <p><strong>Code</strong>:</p>
  <pre><code>package com.tui.structure_json;
  import java.util.Map;
  import java.util.Set;
  
  import com.google.gson.JsonElement;
  import com.google.gson.JsonObject;
  import com.google.gson.JsonParser;
  
  public class App 
  {
      public static void main( String[] args )
      {
          String yourJson = &quot;{\r\n&quot; + 
                  &quot;   \&quot;payload\&quot;: {\r\n&quot; + 
                  &quot;       \&quot;giata\&quot;: {\r\n&quot; + 
                  &quot;           \&quot;435185\&quot;: [\r\n&quot; + 
                  &quot;               \&quot;2019-11-27T14:34:32.368197Z\&quot;\r\n&quot; + 
                  &quot;           ]\r\n&quot; + 
                  &quot;       },\r\n&quot; + 
                  &quot;       \&quot;dod1\&quot;: {\r\n&quot; + 
                  &quot;           \&quot;A0947863\&quot;: [\r\n&quot; + 
                  &quot;               \&quot;2019-11-27T14:34:32.368197Z\&quot;\r\n&quot; + 
                  &quot;           ]\r\n&quot; + 
                  &quot;       },\r\n&quot; + 
                  &quot;       \&quot;gr\&quot;: {\r\n&quot; + 
                  &quot;           \&quot;A0947863\&quot;: [\r\n&quot; + 
                  &quot;               \&quot;2019-11-27T14:34:32.368197Z\&quot;,\r\n&quot; + 
                  &quot;               \&quot;2021-04-27T06:13:12.841968Z\&quot;,\r\n&quot; + 
                  &quot;               \&quot;2021-04-27T06:13:21.640612Z\&quot;,\r\n&quot; + 
                  &quot;               \&quot;2021-04-27T06:13:28.439001Z\&quot;,\r\n&quot; + 
                  &quot;               \&quot;2021-04-27T06:13:43.487103Z\&quot;,\r\n&quot; + 
                  &quot;               \&quot;2021-04-27T06:13:49.770269Z\&quot;\r\n&quot; + 
                  &quot;           ]\r\n&quot; + 
                  &quot;       }\r\n&quot; + 
                  &quot;   }\r\n&quot; + 
                  &quot;}&quot;;
          JsonElement element = JsonParser.parseString(yourJson);
          JsonObject obj = element.getAsJsonObject(); //since you know it's a JsonObject
          Set&lt;Map.Entry&lt;String, JsonElement&gt;&gt; entries = obj.entrySet();//will return members of your object
          for (Map.Entry&lt;String, JsonElement&gt; entry: entries) {
              System.out.println(entry.getValue());
          }
      }
  }
  </code></pre>