JSONArray append JSONObject or PsiElement


Hello I am trying to add an element to empty JsonArray but it doesn't actually add it within the array itself but after the array key object in a JsonFile. Basically I am trying to add an element within the array itself not after the array bracket. Any examples on doing this? Code snippet.  Is this the proper approach?


JsonArray statementArray = (JsonArray)((JsonProperty)child).getValue()
jsonElementGenerator.createProperty("Key", "Value")
1 comment
Comment actions Permalink

It is hard to understand the issue without the full context (full code, example of object before/after adding, what is property1,, what is statementArray at the moment of adding, etc).
I suggest taking a look at com.intellij.json.psi.JsonPsiUtil#addProperty() in the IntelliJ Platform code (it adds a property to an object, but it should be similar).


Please sign in to leave a comment.