title: Creating nested JSON object for the following structure in Java using JSONObject?
body: <p>I want to build a JSON Object similar to following the structure in java using JSONObject and JSONArray.</p>
  
  <p>I have gone through various posts in stack overflow, which suggests using methods like push, put etc which I am unable to identify for JSONArray. Please help. </p>
  
  <pre><code>{
      "name": "sample",
      "def": [
          {
              "setId": 1,
              "setDef": [
                  {
                      "name": "ABC",
                      "type": "STRING"
                  },
                  {
                      "name": "XYZ",
                      "type": "STRING"
                  }
              ]
          },
          {
              "setId": 2,
              "setDef": [
                  {
                      "name": "abc",
                      "type": "STRING"
                  },
                  {
                      "name": "xyz",
                      "type": "STRING"
                  }
              ]
          }
      ]
  }
  </code></pre>