Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding empty array to a JSON object

Tags:

I am trying to create a JSON object that looks like the below :

{"filters": {"defaultOperator":"OR", "filters":[]}}

What should i add to my JSON object to make a empty array object ??. Cant get my head around an empty array .

tried jo1.put("filters",new Object[0]);. This did not work .

I am testing an API which requires these array filled only in special cases, most of the time its empty. But dont know how to add it. I am creating the entry JSON like

JSONObject jo1 = new JSONObject();
                 jo1.put("defaultOperator", "OR");
                 jo1.put("filters","[]");

                 jo3 = new JSONObject();
                 jo3.put("filters", jo1);

                 //Toast.makeText(getApplicationContext(),""+jo3.toString() , Toast.LENGTH_LONG).show();


                 //json = new GsonBuilder().create().toJson(comment1, Map.class);
                 httppost.setEntity(new StringEntity(jo3.toString()));