I don't know if I understand you correctly but maybe this example can help you.
1) You can use jackson to work with json and for that you have to download 2 jars:
http://central.maven.org/maven2/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar
http://central.maven.org/maven2/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar
2) Create the next classes:
The first class is to receive you input
public class Input {
private String key;
private String value;
private String element;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getElement() {
return element;
}
public void setElement(String element) {
this.element = element;
}
}
The second class has the array of elements that you want
public class Output {
private String key;
private String value;
private String[] element;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String[] getElement() {
return element;
}
public void setElement(String[] element) {
this.element = element;
}
}
The third one is created to apply the conversions and run the program
import org.codehaus.jackson.map.ObjectMapper;
public class TestJson {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
String originalString ="{\"key\":\"my key\",\"value\":\"my value\",\"element\":\"X\"}";
System.out.println(" Input: " + originalString);
Input input = mapper.readValue(originalString, Input.class);
String[] element = {input.getElement()};
Output output = new Output();
output.setKey(input.getKey());
output.setValue(input.getValue());
output.setElement(element);
String result = mapper.writeValueAsString(output);
System.out.println("Result: " + result);
}
}
After run TestJson you will see your expected result
Input: {"key":"my key","value":"my value","element":"X"}
Result: {"key":"my key","value":"my value","element":["X"]}