title: How to return json object having particular value in java?
body: <p>This is what I have as a json and I have one condition here to ignore the object which has object_name:[parent],I had tried somthing which didnt worked out can someone help me with the same</p>
  <pre><code>    [
    {
      &quot;object_group&quot;: &quot;Trans&quot;,
      &quot;permission_values&quot;: [
        {
          &quot;object_type&quot;: &quot;Trans&quot;,
          &quot;permission_type&quot;: [
            {
              &quot;View&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Invoice&quot;
          ]
        },
        {
          &quot;object_type&quot;: &quot;Trans&quot;,
          &quot;permission_type&quot;: [
            {
              &quot;View&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;parent&quot;
          ]
        }
      ]
    },
    {
      &quot;object_group&quot;: &quot;General&quot;,
      &quot;permission_values&quot;: [
        {
          &quot;object_type&quot;: &quot;General&quot;,
          &quot;permission_type&quot;: [
            {
              &quot;View&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Customer&quot;
          ]
        },
        {
          &quot;object_type&quot;: &quot;General&quot;,
          &quot;permission_type&quot;: [
            {
              &quot;Delete&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Product&quot;
          ]
        }
      ]
    }
  ]
  </code></pre>
  <p>This is the actual Thing I tried which I got as from one I have one condition here to ignore the object which has object_name :[parent]</p>
  <pre><code> import java.util.ArrayList;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Set;
  
  import org.json.JSONArray;
  import org.json.JSONObject;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.JsonMappingException;
  import com.fasterxml.jackson.databind.JsonNode;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.fasterxml.jackson.databind.node.ArrayNode;
  import com.fasterxml.jackson.databind.node.ObjectNode;
  
  public class TestData {
  
      public static void main(String[] args) throws JsonMappingException, JsonProcessingException {
  
           String input = &quot;{\&quot;JSON_OBJECT\&quot;:[{\&quot;object_type\&quot;:\&quot;Trans\&quot;,\&quot;permission_type\&quot;:[{\&quot;View\&quot;:true}],\&quot;object_name\&quot;:[\&quot;Invoice\&quot;]},{\&quot;object_type\&quot;:\&quot;General\&quot;,\&quot;permission_type\&quot;:[{\&quot;View\&quot;:true}],\&quot;object_name\&quot;:[\&quot;Customer\&quot;]},{\&quot;object_type\&quot;:\&quot;Trans\&quot;,\&quot;permission_type\&quot;:[{\&quot;View\&quot;:true}],\&quot;object_name\&quot;:[\&quot;Payments\&quot;]},{\&quot;object_type\&quot;:\&quot;General\&quot;,\&quot;permission_type\&quot;:[{\&quot;Delete\&quot;:true}],\&quot;object_name\&quot;:[\&quot;Product\&quot;]}]}&quot;;
              ObjectMapper objectMapper = new ObjectMapper();
              JsonNode jsonNode = objectMapper.readTree(input);
              Iterator&lt;JsonNode&gt; jsonObject = jsonNode.get(&quot;JSON_OBJECT&quot;).iterator();
              ObjectNode objectNode = objectMapper.createObjectNode();
  
              while (jsonObject.hasNext()) {
                  JsonNode node = jsonObject.next();
                  String object_type = node.path(&quot;object_type&quot;).asText();
                  if (objectNode.has(object_type)) {
                      JsonNode objectTypeNode = objectNode.get(object_type);
                      JsonNode permission_values = objectTypeNode.path(&quot;permission_values&quot;);
                      if (!permission_values.isMissingNode()) {
                          ObjectNode permissionNode = objectMapper.createObjectNode();
                          node.fields().forEachRemaining(kv -&gt; permissionNode.set(kv.getKey(),kv.getValue()));
                          ((ArrayNode) permission_values).add(permissionNode);
                      } else {
                          ObjectNode permissionNode = objectMapper.createObjectNode();
                          node.fields().forEachRemaining(kv -&gt; permissionNode.set(kv.getKey(),kv.getValue()));
                          ((ArrayNode) permission_values).add(permissionNode);
                      }
                  } else {
                      ArrayNode permissionArrayNode = objectMapper.createArrayNode();
                      ObjectNode permissionNode = objectMapper.createObjectNode();
                      node.fields().forEachRemaining(kv -&gt; permissionNode.set(kv.getKey(),kv.getValue()));
                      permissionArrayNode.add(permissionNode);
                      ObjectNode permNode = objectMapper.createObjectNode();
                      permNode.set(&quot;permission_values&quot;, permissionArrayNode);
                      objectNode.set(object_type, permNode);
                  }
              }
              ArrayNode arrayNode = objectMapper.createArrayNode();
              objectNode.fieldNames().forEachRemaining(key -&gt;{
                  ObjectNode node = objectMapper.createObjectNode();
                  node.put(&quot;object_group&quot;,key);
                  objectNode.get(key).fields().forEachRemaining(kv -&gt; node.set(kv.getKey(),kv.getValue()));
                  arrayNode.add(node);
              });
              System.out.println(arrayNode.toString());
      }
  }
  </code></pre>
  <p>Expected output:-
  can someone pls help me to get this output ..</p>
  <pre><code>[
    {
      &quot;object_group&quot;: &quot;Trans&quot;,
      &quot;permission_values&quot;: [
        {
          &quot;permission_type&quot;: [
            {
              &quot;View&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Invoice&quot;
          ]
        }
      ]
    },
    {
      &quot;object_group&quot;: &quot;General&quot;,
      &quot;permission_values&quot;: [
        {
          &quot;permission_type&quot;: [
            {
              &quot;View&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Customer&quot;
          ]
        },
        {
          &quot;permission_type&quot;: [
            {
              &quot;Delete&quot;: true
            }
          ],
          &quot;object_name&quot;: [
            &quot;Product&quot;
          ]
        }
      ]
    }
  ]
  </code></pre>