csandreas1
csandreas1

Reputation: 2378

construct a url with input parameters from json

I am receiving a json response to construct a parameterized string in JavaScript. However I need to pass actual parameters from JavaScript on some properties e.g. custom_input has to change dynamically.

[{ "road_name_gr": "custom_input" "town_code" : 1 }]

Then I read that json file and convert that to a url.

cql_filter = new URLSearchParams(json_file).toString();  

output: town_code=1&road_name_gr=custom_input

However I have to "modify" the url to accept input.

e.g. 'town_code=1&road_name_gr=' + my_custom_input

Upvotes: 0

Views: 132

Answers (1)

Jiho Lee
Jiho Lee

Reputation: 987

Try this:

my_custom_input = decodeURIComponent(my_custom_input) // URI Decode
let input_params = new URLSearchParams(json_file);
input_params.set("road_name_gr", my_custom_input);
cql_filter = input_params.toString();

You have to set parameter before obtain string value.

Upvotes: 1

Related Questions