title: getJSONArray from root objects in JSON format - Java
body: <p>I've been spending the last couple of days trying to format a JSON string into a JSON object, but this is not quite the usual json string. Im receiving it from an url and have no problem converting it into a string but when im going to create the JSON object Ive found a whole lot of issues.
  The JSON looks like this:</p>
  
  <pre><code>header {
    gtfs_realtime_version: "1.0"
    incrementality: FULL_DATASET
    timestamp: 1511789066
  }
  entity {
    id: "294-131-39-562-4732025"
    vehicle {
      trip {
        trip_id: "131-39-562-4732025"
        route_id: "131"
      }
      position {
        latitude: 3.44351
        longitude: -76.52622
      }
      timestamp: 1511789065
      stop_id: "501450"
      vehicle {
        id: "21002"
        label: "MC21002"
        license_plate: "VCQ452"
      }
    }
  }
  entity {
    id: "1087-431-55-35-4732025"
    vehicle {
      trip {
        trip_id: "431-55-35-4732025"
        route_id: "431"
      }
      position {
        latitude: 3.3767517
        longitude: -76.54276
      }
      timestamp: 1511789065
      stop_id: "502150"
      vehicle {
        id: "31038"
        label: "MC31038"
      }
    }
  }
  </code></pre>
  
  <p>as you can see there is no array, nor commas separating the element that I need to process (entity), I cant even get the JSONObject from the root.
  Any suggestions?
  This is the last block of code I've tried in which I remove the header, insert all the entity objects into the array buses, and separate them by commas, but is no use</p>
  
  <pre><code>//getRespuesta(); gives me the string 
  //Log.d("LIVE", "RAW JSon: " + getRespuesta()); 
  String[] parts = getRespuesta().split("[}]", 2);
  
  
  String[] splitter = parts[1].split("(?=entity)");
  
  String finalString = splitter[1];
  
  for (int t = 2; t &lt; splitter.length; t++) {
      finalString = finalString + ",\n" + splitter[t];
  }
  
  Log.d("LIVEL", "SIZE: " + splitter[1]);
  
  String JSonChunk = "{ \n \"buses\": [ \n " + finalString + "\n ] \n }";
  //String JSonChunk = "{ \n " + parts[1] + "\n }";
  try {
  
  
     // Log.d("LIVE", "CHUNKED JSon: " + JSonChunk);
      JSONObject json = new JSONObject(JSonChunk);
  }catch........
  </code></pre>