setJSONArray should start a new line when inserting an array into a JSON object

What makes you think so? The opening curly bracket you are talking about is valid JSON in either of the places you have shown it.