how to form json obejct

create json object java
create json object in javascript dynamically
get value from json object in javascript
create json object online
json example
json format
how to get key and value from json array object in javascript
create json array in javascript

I want to convert the following JSON using JsonObect and JsonArray but not able to do so.

  "query": {
    "bool": {
      "must": [
          "match": {
            "customer.partnerName": "Synapse"
          "range": {
            "customer.billing.chargeAmount": {
              "gte": 1,
              "lte": 100
      "filter": [
          "match": {
            "customer.configId": 15

I have tried using JsonObject but not able to achieve the result.

This is just plain copy/paste of your json string into AndroidStudio, it splits the string automatically and adds escape slashes.. it looks horrible but the syntax you wrote is perfectly ok..

    String jsonString = " {\n" +
            "                        \"query\": {\n" +
            "                        \"bool\": {\n" +
            "                            \"must\": [\n" +
            "                                    {\"match\": \n" +
            "            { \"customer.partnerName\":   \"Synapse\"  }},\n" +
            "\n" +
            "                                    {\n" +
            "\"range\" : \n" +
            "{\n" +
            "                                        \"customer.billing.chargeAmount\" : {\n" +
            "                                            \"gte\" : 1,\n" +
            "                                            \"lte\" : 100\n" +
            "                                        }\n" +
            "                                    }}\n" +
            "                            ],\n" +
            "                            \"filter\": [\n" +
            "                                    { \"match\":  { \"customer.configId\": 15 }}\n" +
            "                            ]\n" +
            "                        }\n" +
            "                    }\n" +
            "                    }";

    /*jsonString = "{\"query\":{\"bool\":{\"must\":[{\"match\":{\"customer.partnerName\":\"Synapse\"}},{\"range\":{\"customer.billing.chargeAmount\":{\"gte\":1,\"lte\":100}}}],\"filter\":[{\"match\":{\"customer.configId\":15}}]}}}";

    try {
        JSONObject object = new JSONObject(jsonString);

    } catch (JSONException e) {

the second option you have is to create the object and inner objects and arrays programmatically.. like this..

    try {

        JSONObject jsonObject = new JSONObject();

        JSONObject query = new JSONObject();
        jsonObject.put("query", query);

        JSONObject bool = new JSONObject();
        query.put("bool", bool);

        JSONArray must = new JSONArray();
        bool.put("must", must);

        JSONObject matchWrap = new JSONObject();

        JSONObject match = new JSONObject();
        match.put("customer.partnerName", "Synapse");

        matchWrap.put("match", match);


        JSONObject rangeWrap = new JSONObject();

        JSONObject range = new JSONObject();

        JSONObject customerBillingChargeAmount = new JSONObject();
        customerBillingChargeAmount.put("gte", 1);
        customerBillingChargeAmount.put("lte", 100);

        range.put("customer.billing.chargeAmount", customerBillingChargeAmount);

        rangeWrap.put("range", range);


        JSONArray filter = new JSONArray();
        bool.put("filter", filter);

        JSONObject match2Wrap = new JSONObject();

        JSONObject match2 = new JSONObject();
        match2.put("customer.configId", 15);

        match2Wrap.put("match", match2);


        String jsonString2 = jsonObject.toString();


    } catch (JSONException e) {

This yields the same rasult as your input string when stripped of whitespaces tabs linefeeds etc..

JSON Objects, Creating Simple Objects. JSON objects can be created with JavaScript. Let us see the various ways of creating JSON objects using JavaScript −. Creation of an​  Get complete form data as array and json stringify it. var formData = JSON.stringify($("#myForm").serializeArray()); You can use it later in ajax. Or if you are not using ajax; put it in hidden textarea and pass to server. If this data is passed as json string via normal form data then you have to decode it using json_decode. You'll then get all data in an array.

I think what you're looking for is json parsing. This is done in the following way:

JsonParser parser = new JsonParser();
JsonObject object = (JsonObject) parser.parse(jsonData); //Insert json string data
//Do other stuff

JSON - Objects, JSONArray may be what you want. String message; JSONObject json = new JSONObject(); json.put("name", "student"); JSONArray array = new  JSON can actually take the form of any data type that is valid for inclusion inside JSON, not just arrays or objects. So for example, a single string or number would be a valid JSON object. Unlike in JavaScript code in which object properties may be unquoted, in JSON only quoted strings may be used as properties.

var txt = '{"query": {"bool": {"must": [{"match": { "customer.partnerName":   "Synapse"  }},{"range" : {                                        "customer.billing.chargeAmount" : {                                            "gte" : 1,                                            "lte" : 100                                        }                                    }}],"filter": [{ "match":  { "customer.configId": 15 }}]}}}'
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.query;

How to create JSON Object using String?, To understand how to work with data stored in JSON, and create your own JSON objects. No, really, what is  Next, we will serialize the class object that we defined into JSON using JsonConvert.SerializeObject. Let’s store the serialized data inside a string variable. string JSON result = JsonConvert.SerializeObject(emp); Now, we have serialized the data into JSON structure, but we will need to save the data somewhere, so we will provide a path.

Hace you tried to Google gson ? Here is the repo, also you can find relevant implementations online as well.

Working with JSON, A simple, dependency-free way to use `reduce()` to convert all the fields in a form to a JSON object for AJAX (or whatever). jQuery provides a very simple method that helps us create our JSON data object. This method is the serializeArray. To use it, all we are going to create a new JavaScript method and pass in our form reference function ConvertFormToJSON(form) { }

Try this:-

                 JSONObject jsonObject = new JSONObject(/*Pass your string value here*/ new JSONTokener(result.toString()).nextValue().toString());

             //get 'query' as JSONObject
              JSONObject jresponseData = new JSONObject(jsonObject.getString("query"));

              //since 'bool' is insode 'query'
              JSONObject jresponseData_2 =jresponseData.getString("bool");

              JSONArray jsonArray = new JSONArray(jresponseData_2.getString("must"));

And you will get the result in JSONArray

How to Convert HTML Form Field Values to a JSON Object · Learn , Download Create Json Object In Javascript Example PDF. Download Create Json Object In Javascript Example DOC. Plain old internet would provide a create  Build Bootstrap 4 Forms Based On JSON - bs-jsonform. Easy Form Generator With JS Object & JSON Schema - cleverform. Simple Form Builder With JSON Schema - jQuery JSONForm. JSON To Form And Form To JSON Converter - jQuery jform. Build HTML Form From JSON Schema - jQuery JSON Form. Populate Form Fields With JSON Data - json-form-binding.js

Create Json Object In Javascript Example, 9. 10. 11. 12. 13. 14. 15. 16. {. "array": [. 1,. 2,. 3. ],. "boolean": true,. "color": "gold",. "null": null,. "number": 123,. "object": {. "a": "b",. "c": "d". },. "string": "Hello World". }. Step 2: Extract the Values of Form Fields As JSON Step 2.1 — Understand how reduce()works.. The reduce()method uses a function to convert an array into a single value. Step 2.2 — Deconstruct the function.. A reducer functionto combine our form elements into a single object. An initial Step 2.3 —

JSON Editor Online, For single objects we use JSONObject alone which is an easy task. You can see the example code piece below. # creating a JSON String (directly executed via  Recently, whilst working on a project I needed to take HTML FormData and then convert it to JSON to be sent off to an API. By default the FormData object does not work in the way you would want it to for JSON. Using the for..of syntax introduced in ECMAScript 2015, we can access the form data entries and iterate over them to get key and value

Creating a JSON String from JSON Object and JSON Arrays in , A JSON value can be another JSON object, array, number, string, boolean (true/​false) or null. Creating JSON Directly from JSONObject. JSON data is written as name/value pairs, just like JavaScript object properties. A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value: "firstName":"John"