How to pass a JSON array as a parameter in URL

How to pass a JSON array as a parameter in URL

how to pass json object in url javascript
how to pass json object in url c#
how to pass json object in get request
json in url example
how to pass json object in url in java
how to pass json object in url python
json to url
how to pass json object in url get

I have an requirement to pass a some values from mobile to server in a web service call and so I am planning to pass all the values in JSON format like the below

    "nameservice": [
            "id": 7413,
            "name": "ask"
            "id": 7414,
            "name": "josn"
            "id": 7415,
            "name": "john"
            "id": 7418,
            "name": "R&R"

The following is my service call

public String saveName(String acc)
{jsonObject = new JSONObject();
    jsonObject.accumulate("result", "saved ");
    catch(Exception e)
        e.printStackTrace();jsonObject.accumulate("result", "Error Occured ");
    return jsonObject.toString();

I am trying to call the above service by this way

localhost:8080/service/saveName?acc={ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": "john" }, { "id": 7418, "name": "R&R" } ] }

But the output is like this

{ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": "john" }, { "id": 7418, "name": "R

Can any body please tell me why I am not getting all the values please?

I would suggest to pass the JSON data in the body as a POST request.But if you still want to pass this as a parameter in URL,you will have to encode your URL like below just for example:-

for ex json is :->{"name":"ABC","id":"1"}


for more information on URL encoding refer below

How do I put a JSON object in a URL as a GET parameter? : javascript, Say I want to pass data: { Name: 'Jack' },. To a URL JSON itself is a string. To turn your object into JSON you simply need to call a JSON.stringify(obj). Make sure you url-encode the string as well with encodeURI() before appending it to a link. So that gave me opportunity to learn about new jQuery.param() which converts the JSON/Array into query string. Let us look at few examples below : Let us look at few examples below : var myParams = {country:"US", customerId:"1"} jQuery.param(myParams); Output: "country=US&customerId=1"

I know this could be a later post, but, for new visitors I will share my solution, as the OP was asking for a way to pass a JSON object via GET (not POST as suggested in other answers).

  1. Take the JSON object and convert it to string (JSON.stringify)
  2. Take the string and encode it in Base64 (you can find some useful info on this here
  3. Append it to the URL and make the GET call
  4. Reverse the process. decode and parse it into an object

I have used this in some cases where I only can do GET calls and it works. Also, this solution is practically cross language.

What is the correct way to pass JSON objects in an http request , You could use url params : http://localhost:5555/company/name/cuthbert/address​/mainst. Or pass the json object as a string query param. JavaScript Object Notation (JSON) is a convenient way to pass values back and forth between your website pages. JSON takes over where XML left off. While XML is still popular for some legacy applications, JSON is the newest format and useful to know as a developer.

You can pass your json Input as a POST request along with authorization header in this way

public static JSONObject getHttpConn(String json){
        JSONObject jsonObject=null;
        try {
            HttpPost httpPost=new HttpPost("");
            org.apache.http.client.HttpClient client = HttpClientBuilder.create().build();
            StringEntity stringEntity=new StringEntity("d="+json);

            httpPost.addHeader("content-type", "application/x-www-form-urlencoded");
            String authorization="test:test@123";
            String encodedAuth = "Basic " + Base64.encode(authorization.getBytes());        
            httpPost.addHeader("Authorization", security.get("Authorization"));
            HttpResponse reponse=client.execute(httpPost);
            InputStream inputStream=reponse.getEntity().getContent();
            String jsonResponse=IOUtils.toString(inputStream);
            } catch (UnsupportedEncodingException e) {

        } catch (ClientProtocolException e) {

        } catch (IOException e) {

        return jsonObject;


This Method will return a json response.In same way you can use GET method

How to send array as parameter in API Call??, Here's how I pass JSON to a micro-service (example below just takes the passed JSON, "pretty-prints" it and returns it to FMP):. Insert from URL [ Select ; With  I want to pass json object as a query string parameter (not from body) to ASP.NET Core Web API url from postman. Kindly let me know how to pass? below the sample JSOB object structure : here, 'names's is string array

& is a keyword for the next parameter like this ur?param1=1&param2=2

so effectively you send a second param named R". You should urlencode your string. Isn't POST an option?

JQuery : create URL query string from JSON/Array, Hi Friends, I was writing javascript to reload my page with different parameters. So I needed to create the queryString of those parameters but I  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more how to send an array in url request

I know this is old, but if anyone else wants to know why they get incomplete json like above is because the ampersand & is a special character in URLs used to separate parameters. In your data there is an ampersand in R&R. So the acc parameter ends when it reaches the ampersand character.

That's why you are getting chopped data. The solution is either url encode the data or send as POST like the accepted solution suggests.

Arrays in query params - RAML by Example, JSON API. A client MAY request that an endpoint return only specific fields in the response on a per-type basis by including a fields[TYPE]  @ashfurrow yeah I was working under the assumption that perhaps Jimmy wanted to send an array as a parameter. If what he wants is send a JSON array then yeah I guess .Custom would be needed. Maybe let's wait until he can clarify if he meant the array parameter or the parameters as an array 😄

How To Pass Json Object In Url Post, Pass PHP Arrays to JSON and JS with json_encode. The id parameter can be either the canonical URL of your object or the ID of the object instance in the  It is quite a common practice to send list/array of values to a Rest API. In spring we can handle these cases very easily. Let’s see how to send a list of query parameters, and receive them in

Write many entries to a channel in JSON format with a single HTTP , Body Parameters and Object Members. The body of the bulk JSON write operation is a JSON object with the members and arrays listed in these tables. I feel like I lose, at least in the context of hapi and joi, the ability to quickly validate and reject a request if it fails validation if I'm just passing JSON objects as strings. But url parameters in my example make sense. Am I still resigned to converting the JSON to a string for anything more complex? – Cuthbert Apr 13 '16 at 14:47

Invoking JSON Web Services – Liferay Help Center, As with passing parameters as part of a URL path, To pass a List argument, send a JSON array. As with passing parameters as part of a URL path, the parameter order is not important, and the best match rule applies for overloaded methods. Now you know a few different ways to pass parameters. It’s also possible to pass URL parameters in a mixed way. Some can be part of the URL path and some can be specified as request parameters.