Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info

    This is my JSON -
    "app_site": "eventsubscribers",
    "app_branch": "master",
    "app_dbhash": false,
    "app_env": "production",
    "app_rev": "",
    "app_tar": "eventsubscribers-master-"
    "app_site": "subscribers",
    "app_branch": "master",
    "app_dbhash": false,
    "app_env": "production",
    "app_rev": "",
    "app_tar": "subscribers-master-"
    This is my controller -

         public class statusController {
    public status getAllstatus() throws IOException, IllegalAccessException, Throwable, Exception{
        byte[] jsonData=Files.readAllBytes(Paths.get("C:/Users/patrag/workspace/com.json2rest/ver.json"));
        ObjectMapper objectMapper = new ObjectMapper();
        status stat1 = objectMapper.readValue(jsonData, status.class);
        return stat1;


    Now I want both the app_sites followed by their respective app_tar in the browser. How should I proceed ? As of now returning the whole object gives me RAW JSON data as o/p but I dont want the complete JSON, only particular fields of objects and their respective values (i.e app_site followed by the app_tar)

    Tom Marrs

    You need to filter the JSON data to reduce it just those 2 fields. Use jq to do this. Take a look at the jq Manual.

    After you get comfortable with jq, use the following query:

    Tom Marrs
    [.[] | { app_site, app_tar}]
    Then, update your code:
    1. Convert the jsonData byte array to a String so you can modify the data.
    2. Use the jackson-jq library to use jq from Java, and apply the above jq query. You'll use the String version of jsonData as input. Follow (jackson-jq Basic Example)[https://github.com/eiiches/jackson-jq#basic-example].
    3. Take the result (should be of type List<JsonNode>) and add it to Object Mapper. You'll need to figure this out yourself.
    Please let me know if this helps.