Problem with single-quote mark in JSON

I would think this is a common issue, but I've not been able to find a solution. I am trying to index an item that has an apostrophe (single-quote) character in it. When I execute cURL from the command line, I'm thrown into the cURL interactive mode. I figured I'd just escape the apostrophe ('), but that made no difference. Here is my test:

curl -XPOST 'http://localhost:9200/twitter/tweets/' -d '{"twitter_id":"tag:search.twitter.com,2005:00000000000","message":"I can't wait."}'

Is there maybe a problem with the cURL configuration on my Mac?

Try like this;

curl -XPOST 'http://localhost:9200/twitter/tweets/' -d @- <<EOF { "twitter_id" : "tag:search.twitter.com,2005:00000000000", "message" : "I can't wait." } EOF

Thanks for the suggestion -- I tried it, but got the same result. I
end up getting to the > cursor.

On Jan 3, 3:53 pm, harryf hfue...@gmail.com wrote:

Try like this;

curl -XPOST 'http://localhost:9200/twitter/tweets/'-d @- <<EOF
{
"twitter_id" : "tag:search.twitter.com,2005:00000000000",
"message" : "I can't wait."}

EOF

--
View this message in context:http://elasticsearch-users.115913.n3.nabble.com/Problem-with-single-q...
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Hi
Can you try replacing single quote with double single quote for eg replace ' with ''.

On Mon, 2011-01-03 at 13:19 -0800, searchersteve wrote:

I would think this is a common issue, but I've not been able to find a
solution. I am trying to index an item that has an apostrophe (single-quote)
character in it. When I execute cURL from the command line, I'm thrown into
the cURL interactive mode. I figured I'd just escape the apostrophe ('),
but that made no difference. Here is my test:

curl -XPOST 'http://127.0.0.1:9200/twitter/tweets' -d '
{
"twitter_id" : "tag:search.twitter.com,2005:00000000000",
"message" : "I can\u0027t wait"
}
'

clint

Thanks, Clint! That worked. I am using an older version of PHP that lacks json_encode, so I used a class called Services_JSON instead. The json_encode function for PHP5+ includes an option to convert the ' character.

If I am opening my indexed data from ES as an API, what do I need to tell developers about expecting the \u0027 ?

Separately, if this is a standard issue with injecting JSON into ES, should it maybe be part of the documentation?

Steve

On Mon, 2011-01-03 at 13:19 -0800, searchersteve wrote: > I would think this is a common issue, but I've not been able to find a > solution. I am trying to index an item that has an apostrophe (single-quote) > character in it. When I execute cURL from the command line, I'm thrown into > the cURL interactive mode. I figured I'd just escape the apostrophe (\'), > but that made no difference. Here is my test:

curl -XPOST 'http://127.0.0.1:9200/twitter/tweets' -d '
{
"twitter_id" : "tag:search.twitter.com,2005:00000000000",
"message" : "I can\u0027t wait"
}
'

clint

On Tue, 2011-01-04 at 11:38 -0800, searchersteve wrote:

Thanks, Clint! That worked. I am using an older version of PHP that lacks
json_encode, so I used a class called Services_JSON instead. The json_encode
function for PHP5+ includes an option to convert the ' character.

If I am opening my indexed data from ES as an API, what do I need to tell
developers about expecting the \u0027 ?

Separately, if this is a standard issue with injecting JSON into ES, should
it maybe be part of the documentation?

\u0027 is just a form of UTF-8 encoding that JSON understands. So any
(compliant) JSON decoder will handle it just fine.

Normally, using any of the ES APIs (Java, Perl, Python, Ruby, JS etc)
you wouldn't need to encode the ' but when using it with curl on the
command line, you're having to account for the shell's own
quoting/escaping - that's where the problem is.

clint

1 Like