Escape values in webhook's JSON payload in Automation for JIRA - json

I have a webhook action configured using Code Barrel's Automation for JIRA add-on. It sends a request to an endpoint that expects a JSON payload.
Using the templating syntax, I can write a custom body like
{"some_key": "{{issue.summary}}"}
to template values into the JSON payload:
However, this is fragile; if any of the templated values contain a double quote or a backslash, we're likely to generate a syntactically invalid JSON payload.
Is there any way in Automation for JIRA to escape text for inclusion within a JSON string?

I just did a quick release that enables you to encode these values. You can find the docs at - https://docs.codebarrel.io/automation/smart-fields/working-with-strings.html#encoding
Though it is pretty simple:
{"some_key": "{{issue.summary.jsonEncode}}"}
This is live in Cloud and available in version 3.9.7 in Server.
Hope that is what you were after.

Related

Unescape JSON from terraform provider

I am developing a custom terraform provider in Go.
I have a JSON parameter like this:
local_context_data = jsonencode({"hello"="world"})
When I check what is sent to the API with TCPdump I can see that the JSON is escaping like this:
{\"hello\":\"world\"}.
But it generates an error because the API is waiting for real JSON without escape.
Do we have a function in Go to unescape this?
Or better: do we have a function in the terraform SDK?
if your API expects json, what you want is probably
local_context_data = {"hello"="world"}
You only need jsonencode if you want to send a json string within the json.

Sonar Issues/search API JSON result has single quotes

I'm using the sonarQube 6.4 web api to get a list of issues
http://sonar-server:9000/api/issues/search?componentKeys=Project_key&sinceLeakPeriod=true&statuses=OPEN,REOPENED&types=BUG
This gives me a Json object which has single quotes,
..."message":"Make this function anonymous by removing its name:
'function() {...}'."...
Because of that highlighted content in the JSON I'm unable to process the JSON from Groovy.
Is the JSON returned by the sonar is valid ?
if so, is there any way to process this kind of JSON in groovy.
Let me know if the full JSON object is needed.
According to http://json.org/ and https://jsonformatter.curiousconcept.com/ the JSON response is valid. Single quotes and brackets {} must not be escaped. The issue comes from your Groovy parser.

how to validate odoo api in postman?

I want to generate a rest api in odoo so that it can be used in other languages. I have used below api's
http://URL_with_PORT/{}/xmlrpc/2/common
http://URL_with_PORT/{}/xmlrpc/2/object
but when I validated it using postman it is giving me error.
You don't need the curly braces in the URL. Just send it to the xmlrpc/2/common endpoint, as per...
http://<server:?port>/xmlrpc/2/common
You need to set the verb to POST, and the body to raw with XML.
Then send in the following XML in the form as per the documentation.
<?xml version='1.0'?>
<methodCall>
<methodName>version</methodName>
</methodCall>
This will return the server version info as per the examples used in the External API documentation in an XML response.
Postman isn't the best client to use XML-RPC calls, take a look at XML RPC GUI for developers in Windows?. You have to create a raw request and then send it. Using SoapUI would be much easier.

How to use JSON response from server to send POST request with parameters from JSON (jmeter)

I have some specific scenario for retrieving Access Token from API using jmeter.
I need to implement following test case and have no idea how to implement this (I am new in jmeter):
Send GET request to server.
Server will return following response: {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600}
After that I need to send POST request to server with parameter of "RequestToken" from step #2.
Thanks!
Answer of Dmitri T really helped me! Thanks a lot!
If your response {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600} is the full one you can add a Regular Expression Extractor Post Processor to GET request configured as follows:
Reference Name: anything meaningful, i.e. token
Regular Expression: {"RequestToken":"(.+?)","Expires":3600}
Template: $1$
After that you can refer to extracted value as ${token} or ${__V(token)} in POST request.
If you need to deal with more complex JSON structures I would recommend using JSON Path Extractor available via JMeter Plugin. It allows fetching data from JSON responses in more "intelligent" way as big JSON entities cannot be easily parsed via regular expressions.
In this case relevant JSON Path query will look like $.RequestToken.
See Using the XPath Extractor in JMeter guide for more details (scroll down to Parsing JSON).
Hope this helps.

How can I handle JSON strings in UniData?

I am receiving JSON strings from a web service. Is there any JSON parsers for UniData?
I am on version 7.2.
If you upgrade to UniData 7.3.x, you will indeed get access to a JSON (and more) parser.
check out the manuals for a new feature called 'U2 Dynamic Objects' - UDO for short.
This will allow you to serialize, access, modified, etc JSON strings.