Sonar Issues/search API JSON result has single quotes - json

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.

Related

Json converted object sent to kafka has quotes escaped with slashes in .net core

when I am serializing my object to json, it is added slashes to all quotes.
same way it is posted to kafka as well. I am trying to see how I can avoid slashes in the json string.
This is built in .net core
string topicmessage = JsonConvert.SerializeObject(item);
I want the json to be like
{"channel":"MOBILE","associationTime":"2022-04-19T00:12:55"}
You have to post the full code to define a bug. it could be just a visualization as a string, but a topicmessage format is ok. Otherwise it could be twice serialized. if you have an error trying to use your json, you can try this
topicmessage=JsonConvert.DeserializeObject<string>(topicmessage);

Unable to Extract value from JSON response which has the data in "\"

Please help me to get out the problem which I am facing. I have a JSON response like this:
"{"Version":10,"Collections":[{"Id":"*******","Name":"","Description":null,"IsValid":false,"ABC":"\\XYZ\\collection\\","C
and want to fetch the values of collections which has n number of Id's but JSON extractor is not working here.
Don't post text as image otherwise even those who are willing to help won't re-type your code or use OCR software in order to reproduce your issue
What you're showing to us is not a valid JSON, you can check it yourself using an offline or online JSON Lint Tool hence you won't be able to use JSON Extractor for this.
If you get escaped JSON as a part of some JSON attribute, like this one:
{
"some-attribute": "{\"foo\":\"bar\"}"
}
You won't be get this bar value directly so you will need to do this in 2 steps:
Use 1st JSON Extractor to get the value of some-attribute
Use 2nd JSON Extractor to get the value of foo attribute
Demo:
More information: API Testing With JMeter and the JSON Extractor

Reading property from JSON object in Javascript with colons

I have a JSON object which I can console log out fine. However whenever I try to read the properties of this object I am getting "Unexpected token :" error. The json object does have a colon in it. How do i escape that colon and console.log the individual properties of the object. See that attached image for info
I think you can try out JSON serializer to get the JSON value. You can't get the JSON value without serializing it. So To serialize, you can use JsonConvert.SerializeObject("Json"). Check it out this link below for JSON serialization.
https://www.newtonsoft.com/json/help/html/SerializingJSON.htm
For serializing the JSON you should install Newtonsoft JSON package in your visual studio.

Jmeter JSON Format Post Processor breaks Token retrieval

I am working with Jmeter and i want to format the JSON results. So i installed JSON Format Post Processor and added it to the root of the project.
It works correctly, it formats the JSon response for easy readability. However there is also a request with requires Token authentication. It does not work with the JSON Format Post Processor.
Example:
Correct coin retrieval without JSON Format Post Processor:
{"access_token":"Secret","expires_in":3600,"token_type":"Bearer"}
And with:
{
"access_token": "Secret",
"expires_in": 3600,
"token_type": "Bearer"
}
I use a regulair extractor to extract the token: access_token":"([a-zA-Z0-9.\-\_]*)
This seems to break in combination with the formatter. No valid token access is denied in all requests
Is there an easy way around this? It seems i can either use Jmeter JSON Format Post Processor for my complete project, or not at all.
Anyone know how i deal with this?
If it is possible, apply JSON Format Post Processor after regex extractor. This could help.
For easier access to data in JSON format you can use JSON Path Extractor or SmartMeter's Boundary Body Extractor
To extract JSON data the best option is native JSON Extractor:
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor
Regarding your precise issue, a better regexp would be:
access_token":"([^"]+?)"
It seems that you have optional white space after :
Regular expression:
access_token":(\s*)"([a-zA-Z0-9.\-\_]*)
Template change to use $2$

How to filter special characters in json?

I use java generated json like this:
[{"nickname":"abc,def"},{"nickname":"abc'def"},{"nickname":"abc"def"}]
when I execute eval(), it raises exception.
I wanna keep comma and quotes in the json.
how to handle this kind of situation?
You have an exception because your json in invalid! How did you generate it? In whatever language you use, build your data structure and call a json encode function (e.g. json_encode in PHP) to generate valid json.
In this specific example, you need to escape the double quote in the last string:
[{"nickname":"abc,def"},{"nickname":"abc'def"},{"nickname":"abc\"def"}]
Note: using eval is not safe, you need to use JSON.parse()!
You need to handle this situation by parsing JSON.
eval() does not parse JSON.
You need to call JSON.parse(), which does parse JSON and will work fine.
The other part of the solution is to generate valid JSON.
"abc"def" is not valid JSON.
You need to change your Java code to use an actual JSON library (such as gson or jackson) which will generate valid JSON.