How do I pass json in the url of a REST request? - json

I am creating a kafka broker in a cluster by sending a request to the url. According to the api it says that I can add additional options to my broker in the form /api/broker/<cli command>?broker={broker-expr}&<setting>=<value>, however the setting that I need to set has json as its value. How would I do this?
I've tried quite a few different ways of writing it at none of them work. The json value is meant to be
{
"period":"10s"
}
I've tried
/api/broker/remove?broker=0&stickiness={"period":"10s"}
/api/broker/remove?broker=8&stickiness={period:10s}
/api/broker/remove?broker=8&stickiness="{period:10s}"
Update:
I've tried encoding the url but it still doesn't work. Everything is decoded except for the :.
The string I enter for the json: %7B%22period%22%3A%22600s%22%7D
This is what it ends up as after I send it.
How do I encode a : ?

Only the first option you suggested is correct JSON. However, the JSON will need to be encoded.
Encoding just the JSON part results in %7B%22period%22%3A%2210s%22%7D
Check out the following site for more on URL encoding
http://www.w3schools.com/tags/ref_urlencode.asp

Related

What is the method to pass a variable to body field in Uipath while using httprequest (json format)?

So, this is what I am working on UiPath..I have slack webhook.. I am POSTing using that webhook.. I have a variable "body" which is of type string.. I want to send that to slack using webhook..
In the body field, I used
"{""text"":"""+body+"""}"
And I checked the status code, it was 400..
And BodyFormat is 'application/json'
I sent a normal text without any concatenation, it worked fine..
the body looks okay to me in how you have it.
You mentioned using POST method, but I'd double check that utilising the "PUT" method
Also check that your Accept Format is set to JSON rather than Any.
No need to change your BodyFormat as "application/json" is correct

How to encode JMeter response body (JSON) to UTF-8?

I use a script where I upload a picture to the website and it returns me all the written data in JSON format.
We use this app to recognize name/surname on different documents, we have Russian documents as well.
However, JMeter returns me something like:
{
"message": "recognized",
"birth_date": "1993",
"native_name": "\u0406\u042e\u041b\u0414\u0410",
"patronymic": "\u0410\u0410\u0410\u0410\u0410"
}
I tried to change encoding in jmeter.properties and system.properties as well, but it didn`t help. Also I tried to change the encoding via PostProcessor in one string, but no result.
By the way, in Postman I get normal result via 'Beautify' section.
Can anyone help with that issue? Maybe any examples of big PostProcessors, which can do it?
It depends on what you're trying to achieve, if you just need these values in their "text" human-readable representation you can get them using i.e. Groovy's JsonSlurper
If you want to substitute the original response with its unescaped equivalent - here is another Groovy's one-liner:
prev.setResponseData(org.apache.commons.lang.StringEscapeUtils.unescapeJava(prev.getResponseDataAsString()),'UTF-8')
put it into JSR223 PostProcessor's "Script" area and it will do the trick for you
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

Pentaho HTTP Post using JSON

I'm brand new to Pentaho and I'm trying to do the following workflow:
read a bunch of lines out of a DB
do some transformations
POST them to a REST web service in JSON
I've got the first two figured out using an input step and the Json Output step.
However I have two problems doing the final step:
1) I can't get the JSON formatted how I want. It insists on doing {""=[{...}]} when I just want {...}. This isn't a big deal - I can work around this since I have control over the web service and I could relax the input requirements a bit. (Note: this page http://wiki.pentaho.com/display/EAI/JSON+output gives an example for the output I want by setting no. rows in a block=1 and an empty JSON block name, but it doesn't work as advertised.)
2) This is the critical one. I can't get the data to POST as JSON. It posts as key=value, where the key is the name I specify in the HTTP Post field name (on the 'Fields' tab) and the value is the encoded JSON. I just want to post the JSON as the request body. I've tried googling on this but can't find anyone else doing it, leading me to believe that I'm just approaching this wrong. Any pointers in the right direction?
Edit: I'm comfortable scripting (in Javascript or another language) but when I tried to use XmlHttpRequest in a custom javascript snippet I got an error that XmlHttpRequest is not defined.
Thanks!
This was trivial...just needed to use the REST Client (http://wiki.pentaho.com/display/EAI/Rest+Client) instead of the HTTP Post task. Somehow all my googling didn't discover that, so I'll leave this answer here in case someone else has the same problem as me.
You need to parse the JSON using a Modified JavaScript step. e.g. if the Output Value from the JSON Output is called result and its contents are {"data"=[{...}]}, you should call var plainJSON = JSON.stringify(JSON.parse(result).data[0]) to get the JSON.
In the HTTP Post step, the Request entity field should be plainJSON. Also, don't forget to add a header for Content-Type as application/json (you might have to add that as a constant)

getting percent ('%') characters and unicode codepoints in HTTP response

I'm connecting to a HTTP API through a simple GET request.
The expected response is a string, representing a JSON, that may contain hebrew (unicode) characters, but i get something like this (pasted only the beginning):
%u007b%u0020%u0022%u0053%u0074%u0061%u0074%u0075%u0073...
the result is the same whether i use ajax or the browser navigation bar directly.
The only place i get the expected json string is in Firefox console, by logging the response object, selecting it, and viewing the responseText property.
I can also replace the percent characters with backslashes, put the result in a unicode parser and get the correct string.
Anybody has any ideas as to what is going on?
The response appears to be encoded with the deprecated javascript function escape() which yields the %uXXXX encoding. If that is the case then the service should instead use encodeURIComponent() or encodeURI() referenced in the link above.
Your current workaround of manual un-encoding is the right way to go until the service is updated.

is it possible to pass json format in browser's url address bar? (GET method)

want to test my url service in browser but need to pass json format data.
I tried the below but no success:
http://locahost:8042/service/getinfo?body={"name":"H&M"}
or any tool that can be use to pass json formatted test data?
UPDATES1
I mean is to pass the json formatted data manually in browser's url address bar. Like as my example above. This is for quick testing only not for implementation.
Yes, you certainly can pass JSON in a URL Querystring. You just have to URLencode the JSON string first. As #dmn said, the data is probably better passed via POST because of GET's size restrictions.
The { and } characters are considered unsafe for unencoded use in a URL.
http://www.faqs.org/rfcs/rfc1738.html
Probably putting it in the GET won't be a good idea, since url parameters have a limit of 256 characters. It would be better if you use POST and put the JSON in the body and after that you can parse it using Jackson for example or gson ... and get the result as an object.
Yes you can Add Extension to chrome web-browser called 'Advance rest Client' and change contain header to application/json and make json object and post in pay load then hit send bottom it works for json object
enter image description here
This is how I am doing in my web service, I am passing a json and within the service I manage it.
Just do a URL query like this:
http://locahost:8042/service/getinfo?name=h%26m
%26 is the encoding of &