I have a requirement to accept JSON String as input in one of the textfield such as input will be like ::
{"order":1}
On form submission i am trying to create request and send this input to http request
var body = ({"key" : input});
var request = {
method : 'POST',
url : '/xxx',
data : body,
headers : {
'Content-Type' : "application/json"
}
};
$http(request).success(function(response) {
}).error(function(response) {
});
but server responds with 400 Bad Request as the body input is formed such as
"key": "{"order":"1"}"
whether as the server expects the input such as
"key": {"order":"1"}
you can see that the " " at start and end of the json are extra appended as the type of the input is text, how can achieve the expected format as mentioned above or any better approach.
Please suggest.
keyanywhere in your code. Your expected string is also malformed.key:valuepair to be used, thanks i have updated the question.