Replace escape character \ from generated JSON string Xamarin.Android - replace

In my Xamarin.Android project, I'm using NewtonSoft Serialization to serialize my Object into JSON string. But when I do this my string has escape characters like this:
{\"id\":\"45912345\",\"number\":\"c6474a2345\"}
But I want like this:
{"id":"45912345","number":"c6474a2345"}
I tried to replace the \ character by:
var data = "{\"id\":\"45912345\",\"number\":\"c6474a2345\"}";
data = data.Replace(#"\","");
but nothing happens. As this is an escape character, this is not printed on console, but I need to send this as form data to my Rest API.
How do I get a valid JSON string?

Related

Special (Meta) Characters while using Regular Expression Extractor in JMeter

In a response : there is a string like this.
,"Software":"abcde",
and i want to select abcde
i write the regular Expression as ,"Software":"([^"]+)",
then i used this variable in a GET request and a POST request.
in GET request it works but in POST request doesnt.
when i look at the post request i see some % characters. but they are not included in abcde string.
in abcde string some special characters like + and / may be present. and they will not transmitted properly to the request.
Why do yo think so? And are there any solution for this?
Check the variable value using Debug Sampler and View Results Tree listener combination, if the variable contains these "special" characters and they should not be there - amend your regular expression accordingly
If your response is in JSON format it worth considering switching to JSON Extractor
With regards to these % and /, can it be connected with URL Encoding?

Escape colon in a Scorched/Sunburnt/Solr search

I'm using scorched for interfacing my Django code with my Solr instance:
response = si.query(DismaxString(querydict.get('q')).execute()
In the data I'm searching I have colons (e.g. Col: Mackay's Reel) and I don't want Solr to interpret that colon as a 'field' query:
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"undefined field Col"
How can I escape all the colons the user enters in the query?
I'm getting an error even on the Solr query interface directly.
For now my workaround is by adding a backslash to each colon via JavaScript before sending the form, so that the colons are sent as ':'.

Get an error when trying to import a CSV using Google Bigquery CLI with backslash as an escape character

When trying to upload a csv file to BigQuery with the following params:
bq load --quote='"' --null_marker='\\N' --source_format=CSV sendpulse.user_orders gs://data-sendpulse/user_orders_3.csv
I get an error when trying to parse the following row:
"0","63800.00","1","0","Service \"Startup Pack\""
Obviously, Bigquery doesn't treat backslash as an escape character for inner quotes, but is there a way to specify backslash as an escape character?
Tried different options and always got errors.
Update:
Quote in a quoted csv value is escaped with another quote and there is no setting for an escape character.
I don't see a better workaround than replacing all \" with ' or "" in your files.

Javascript Storing Regexp screws the original format

I have an angular app where a user can add a regexp in a form, a value like:
github\.com/([A-Za-z0-9\-\_]+)/([A-Za-z0-9\-\_]+)
When I store this in the localStorage and I inspect the localStorage:
github\\\\.com\\/([A-Za-z0-9\\\\-\\\\_]+)\\/([A-Za-z0-9\\\\-\\\\_]+)
When I retrieve in Javascript elsewhere this value I get:
github\\.com\/([A-Za-z0-9\\-\\_]+)\/([A-Za-z0-9\\-\\_]+)
This is not the original regexp and the match method in Javascript can't work.
NOTE: after submitting the form, I store the object with:
localStorage.myobject = JSON.stringify(myobject);
You can get rid of overescaping here, just use
github[.]com/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)
and initialize it via a RegExp constructor so as not to have to escape the regex delimiter /. A dot inside [] loses its special meaning and only matches a literal dot, the hyphen at the end of the character class only matches a literal hyphen, and the _ does not have to be escaped at all anywhere in the pattern:
var tst = "github.com/Test1-Text/Test2";
var pattern = "github[.]com/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)";
console.log(new RegExp(pattern).test(tst));
UPDATE:
When using patterns from external sources, you need to use the constructor notation. Make sure your regex patterns are stored as literal strings (if you had RegExp("C:\\\\Folder"), make sure it is stored as C:\\Folder), and when reading the value in it will be automatically be usable with the RegExp constructor.

Django CharField storing newline

I have a CharField storing user input, including things like "\n" (literally, not by hitting "enter"), which is later used for parsing text with regular expressions. When I fetch the model from the database, however, comparing the value to '\n' fails - it's equal to '\n' instead. How do I unescape it? I do escape it later before insertion into the regular expression, since the field may contain e.g. "*", which I want to be interpreted literally. I tried mark_safe but no luck.
OK I figured it out, thanks to the answers in this question: Python Replace \\ with \
Basically, I needed to do something like that:
separator = processor.separator.decode('string_escape') # Decode
expr = r"<something>" + re.escape(separator) # Escape for the regular expression