Read JSON file

    1

    20

    json
    Java Public Recipes

    Read a JSON file using org.json.simple

    import java.io.FileReader;
    import org.json.simple.JSONArray;
    import org.json.simple.JSONObject;
    import org.json.simple.parser.*;
    
    Object jsonObjectGeneric = new JSONParser().parse(new FileReader("/path/to/your/file.json"));
    JSONObject jsonObject = (JSONObject) jsonObjectGeneric;
    // String attributeValue = (String) jsonObject.get("attribute")
    // JSONArray jsonArray = (JSONArray) jsonObject.get("attributeArray");
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.