# Problem with single-quote mark in JSON

**URL:** <https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734>\
**Category:** Elasticsearch\
**Created:** [January 3, 2011, 9:19pm UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734 "2011-01-03T21:19:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [January 3, 2011, 9:19pm UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/1 "2011-01-03T21:19:04Z")

</div>

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/](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?

---

<div class="post-metadata">

**Author:** ![harryf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harryf/32/3281_2.png) [@harryf](https://discuss.elastic.co/u/harryf)\
**Post date:** [January 3, 2011, 11:53pm UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/2 "2011-01-03T23:53:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [January 4, 2011, 12:23am UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/3 "2011-01-04T00:23:45Z")

</div>

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](mailto:hfue...@gmail.com) wrote:

> Try like this;
> 
> curl -XPOST '[http://localhost:9200/twitter/tweets/'-d](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](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-single-q)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![srrin](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@srrin](https://discuss.elastic.co/u/srrin)\
**Post date:** [January 4, 2011, 3:48am UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/4 "2011-01-04T03:48:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 4, 2011, 9:06am UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/5 "2011-01-04T09:06:24Z")

</div>

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](http://127.0.0.1:9200/twitter/tweets)' -d '  
{  
"twitter\_id" : "tag:search.twitter.com,2005:00000000000",  
"message" : "I can\u0027t wait"  
}  
'

clint

---

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [January 4, 2011, 7:38pm UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/6 "2011-01-04T19:38:52Z")

</div>

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](http://127.0.0.1:9200/twitter/tweets)' -d '  
{  
"twitter\_id" : "tag:search.twitter.com,2005:00000000000",  
"message" : "I can\u0027t wait"  
}  
'

clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 5, 2011, 11:41am UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/7 "2011-01-05T11:41:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:14am UTC](https://discuss.elastic.co/t/problem-with-single-quote-mark-in-json/3734/8 "2017-07-06T04:14:21Z")

</div>


