Escaping "this" or # character in coffeescript - coffeescript

Accessing a web API I'm getting a JSON response similar to:
example: { #param: 1 }
In javascript, I could access this with example.#param but in coffeescript, # is a reserved word and a shortcut for this so it throws an error "Parse error on line #: Unexpected '#'".
How can I access this variable?

Use this notation:
example['#param']

in coffeescript
e={"#param":1}
then
e["#param"] # get #param value
e={#param:1} is not valid javascript if #param not surrounded by quotes , it will be a valid json because in json keys must be quoted.

Related

Using a variable in the Request Body form in Azure Data Factory Copy Data activity

Is it possible to use a variable in the "Request body" field in a Copy data activity?
This is my pipeline:
Output of "Get requestBody":
Allready full of unwanted slashes.
Output of "Set variable":
I using this expression in the "Request body" Field:
#replace(variables('requestBody'),'\','')
This is the input of "Copy data":
I cant get rid of all slashes. Is it even possible to use a variable for "Request body"?
As your lookup activity output returns JSON string value it includes an escape character backslash '\'.
To remove the escape character, create an array type variable and convert the lookup out to JSON array in append variable activity as below.
Create array variable.
Lookup output: As I checked firstrow only property in lookup activity, the output results firstrow only.
In the Append variable activity, get the lookup output and convert it to JSON array.
#json(activity('Lookup1').output.firstrow.requestbody)
Append variable result: Use this variable in later activities.
You can refer to these SO & SO threads for reference.
To remove the backslashes, I had to use this:
#replace(string(variables('requestBody')), '\"', '"')

Insert keywords (double quotes) in mongodb using insert statement. (Escape sequence)

I want to insert a string that contains double quotes and single quotes as below.
db.collectionName.insert({"filedName" : "my field contains "double quotes" and 'single quotes' how to insert"}) ;
When I try insert above, it got error as my field contain double quotes, can some one tell me something like escape sequence to insert double quote?
Can't do as under my field also contain single quotes.
db.collectionName.insert({"filedName" : 'my field contains "double quotes" and 'single quotes' how to insert'}) ;
I think it depends on which context you use your code.
If it's in pure js (node.js for example) you can escape the quote char with \, like this :
db.collectionName.insert({"filedName" : "my field contains \"double quotes\" and 'single quotes' how to insert"}) ;
But in the HTML context it's not possible, you need to replace the double-quote with the proper XML entity representation, "
Consider using grave/accent (`, decimal ASCII code 96) for string enclosing quotes.
JSON allows unicode syntax using \u1234 format according to ECMA-404. Therefore you can use the following syntax to insert double quote and single quotes from MongoDB shell.
db.collectionName.insert({"filedName" : "my field contains \u0022double quotes\u0022 and \u0027single quotes\u0027 how to insert"})
Further, you can use this syntax to insert non-ASCII characters too. This special handling is required if we are forming the JSON manually. If the JSON is being serialized automatically from plain objects (e.g. POJOs) using a framework such as GSON, Xstream the required conversion would happen automatically while converting to JSON.

Why encode url parameter if contains # symbol

I'm passing a URL parameter to a form via a get request. I need to URL encode the parameter when the parameter contains a '#' . Otherwise the request fails. Why is this required ? Why do I need to URL encode the '#' parameter but not other text ?
'#' is used in URLs to indicate where a fragment identifier
(bookmarks/anchors in HTML) begins.
The part following the # is never seen by the server. It is generally used for navigation at the client-end.
The following characters need to be encoded in order to be used literally.
When using GET, anything after # (and the # itself) will not be seen by the server.

Perl JSON pound sign escaping

I am trying to use a web API of a service written in Perl (OTRS).
The data is sent in JSON format.
One of the string values inside the JSON structure contains a pound sign, which in apparently is used as a comment character in JSON.
This results in a parsing error:
unexpected end of string while parsing
JSON string
I couldn't find how to escape the character in order to get the string parsed successfully.
The obvious slash escaping results in:
illegal backslash escape sequence in
string
Any ideas how to escape it?
Update:
The URL I am trying to use looks something like that (simplified but still causes the error):
http://otrs.server.url/otrs/json.pl?User=username&Password=password&Object=TicketObject&Method=ArticleSend&Data={"Subject":"[Ticket#100000] Test Ticket from OTRS"}
Use Uri::escape:
use URI::Escape;
my $safe = uri_escape($url);
See rfc1738 for the list of characters which can be unsafe.
The hash symbol, #, has a special meaning in URLs, not in JSON. Your URL is probably getting truncated at the hash before the remove server even sees it:
http://otrs.server.url/otrs/json.pl?User=username&Password=password&Object=TicketObject&Method=ArticleSend&Data={"Subject":"[Ticket
And that means that the remote server gets mangled JSON in Data. The solution is to URL encode your parameters before pasting them together to form your URL; eugene y tells you how to do this.

Can I use XML::Simple with an in-memory string, rather than a file?

XML::Simple documentation says to initiate the data structure with an XML file, using XMLin('[FILENAME]') ... but I have an in-memory string.
Can I use it directly, or do I need to save it to the filesystem and then load it into XMLin?
You seem to have missed in said documentation the following information:
XMLin() accepts an optional XML
specifier followed by zero or more
'name => value' option pairs. The XML
specifier can be one of the following:
...
A string of XML
A string containing XML (recognised by
the presence of '<' and '>'
characters) will be parsed directly.
eg:
$ref = XMLin('<opt username="bob" password="flurp" />');
It also says
my $ref = $xs->XMLin([<xml file or string>] [, <options>]);