import java.io.*;
import javax.json.*;

/**
 * An example of document-based parsing using JSON-P.
 *
 * @author  Prof. David Bernstein, James Madison University
 */
public class DocumentBasedExample
{
    /**
     * The entry point of the application.
     *
     * @param args  The command line arguments (which are ignored)
     */
    public static void main(String[] args) throws Exception
    {
        BufferedReader in = new BufferedReader(
            new FileReader(
                new File("../../jsonexamples/basics/person.json")));

        // Create the JsonReader
        JsonReader reader = Json.createReader(in);

        // Use the JsonReader to read the JsonObject
        JsonObject person = reader.readObject();

        // Access a top-level attribute of the JsonObject
        System.out.println(person.getString("firstName"));

        // Move into the hierarchy
        JsonObject address = person.getJsonObject("address");        
        System.out.println(address.getString("city"));
    }
}
