How to pass a JSON array as a parameter in URL
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"}
testurl:80/service?data=%7B%22name%22%3A%22ABC%22%2C%22id%22%3A%221%22%7D
for more information on URL encoding refer below
https://en.wikipedia.org/wiki/Percent-encoding
How to escape a JSON string to have it in a URL?
encodeURIComponent(JSON.stringify(object_to_be_serialised))
Convert JavaScript object into URI-encoded string
I'm surprised that no one has mentioned URLSearchParams
var prms = new URLSearchParams({
firstName: "Jonas",
lastName: "Gauffin"
});
console.log(prms.toString());
// firstName=Jonas&lastName=Gauffin
Is there any native function to convert json to url parameters?
Use the URLSearchParams
interface, which is built into browsers and Node.js starting with version 10, released in 2018.
const myParams = {'foo': 'hi there', 'bar': '???'};
const u = new URLSearchParams(myParams).toString();
console.log(u);
How to convert JSON object to JavaScript array?
var json_data = {"2013-01-21":1,"2013-01-22":7};
var result = [];
for(var i in json_data)
result.push([i, json_data [i]]);
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows(result);
http://jsfiddle.net/MV5rj/
Convert array to JSON
Script for backward-compatibility:
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
And call:
var myJsonString = JSON.stringify(yourArray);
Note: The JSON object is now part of most modern web browsers (IE 8 & above). See caniuse for full listing. Credit goes to: @Spudley for his comment below
How to send json data in url as request parameters in java
URL encode your details parameter:
String otherParameter = "374889331-";
String jsonString = "{\"aNumber\":2}";
String url = "editTest.jsp?details=" + URLEncoder.encode(otherParameter + jsonString, "UTF-8");
Related Topics
React How to Fix Failed Prop Type - Invalid Prop of Type String Expected Object
How to Send One Alert from My Node.Js to My JavaScript Client
Why Am I Not Able to Add Input Text into My Table
How to Call a Function When Element Is Loaded At Angular
Why Is React Webpack Production Build Showing Blank Page
Laravel Pdf File Download from Ajax Request (Laravel 5)
How to Fire an Event When V-Model Changes
Javascript Json Parsing Error: Unexpected Token ' in Json At Position 1
How to Combine Two Arrays into One Object With Key Value Pair
React Import: Navigate One Folder Up
Javascript Odd and Even Separation in an Array of Numbers
Mutlple Owl Carousel in One Page With Different Setting
Chart.Js Draw Custom Grid Lines
How to Display Base64 Encoded Pdf
How to Convert Date Format from Dd.Mm.Yyyy to Dd/Mm/Yyyy in JavaScript