You can simply do reverse engineering. Parse your Json String into a Map<String,Object> and that is the map that will give you your Json String if you use some Json library to write it as Json. You can use Json Jackson library or Gson library or any other available. Here is the code That I wrote to do what I just recommended:
private static void jsonParserTest() {
try {
String jsonStr = "{\n" +
" \"PED\": {\n" +
" \"fun\": \"enviarPedido\",\n" +
" \"txtUser\":\"123\",\n" +
" \"md5Passwd\": \"123\", \n" +
" \"arrArticulos\": [\n" +
" [50,10,5,50],\n" +
" [51,9,6.5,58.5],\n" +
" [52,8,7,56],\n" +
" [53,7,8.5,59.5]\n" +
" ]\n" +
" }\n" +
"}";
Map<String, Object> map = JsonUtils.readObjectFromJsonString(jsonStr, Map.class);
System.out.println(map);
System.out.println(JsonUtils.writeObjectToJsonString(map));
} catch (IOException e) {
e.printStackTrace();
}
}
And here is the output:
{PED={fun=enviarPedido, txtUser=123, md5Passwd=123, arrArticulos=[[50, 10, 5, 50], [51, 9, 6.5, 58.5], [52, 8, 7, 56], [53, 7, 8.5, 59.5]]}}
{"PED":{"fun":"enviarPedido","txtUser":"123","md5Passwd":"123","arrArticulos":[[50,10,5,50],[51,9,6.5,58.5],[52,8,7,56],[53,7,8.5,59.5]]}}
So if you create a Map that is described in the first line of an output and then serialize it as JSON you will get your desired JSON
The class JsonUtils used in my sample is a very thin wrapper over Json-Jackson library, but it is very simple to use. It is part of an open source MgntUtils library that is written and maintained by me. Here is a Javadoc for JsonUtils class. The MgntUtils library if you want to use it can be found as Maven artifact on Maven central or On Github (with source code and Javadoc)