title: Parsing JSON in Java Using org.json
body: <p>I have a large file with many JSON objects similiar to the following. I need to parse everything to get the "bought_together" items as an array using the <a href="http://stleary.github.io/JSON-java/index.html" rel="nofollow noreferrer">org.json library</a>. I'm having trouble accessing anything nested in "related".</p>
  
  <p>What is the required code to retrieve "bought_together" as a list?</p>
  
  <pre><code>{
    "asin": "11158732",
    "title": "Girls Ballet Tutu Zebra Hot Pink",
    "price": 3.17,
    "imUrl": "http://ecx.images-amazon.com/images/I/51fAmVkTbyL._SY300_.jpg",
    "related":
    {
      "also_bought": ["L00JHONN1S", "B002BZX8Z6"],
      "also_viewed": ["F002BZX8Z6", "B00JHONN1S", "B008F0SU0Y", "B00D23MC6W", "B00AFDOPDA"],
      "bought_together": ["D202BZX8Z6"]
    },
    "salesRank": {"Toys &amp; Games": 211836},
    "brand": "Coxlures",
    "categories": [["Sports &amp; Outdoors", "Other Sports", "Dance"]]
  }
  </code></pre>
  
  <p>Here is my attempt (Please note, this is within a MapReduce program so some lines may seem out of context.): </p>
  
  <pre><code>JSONObject object = new JSONObject(sampleText); //sampleText is json that has been split by line
  JSONArray boughtTogether = new JSONArray(object.getJSONArray("bought_together"));
  </code></pre>