# How to write quotes and double quotes in the same String

**URL:** <https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465>\
**Category:** Logstash\
**Created:** [October 8, 2018, 1:45pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465 "2018-10-08T13:45:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre2](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pierre2](https://discuss.elastic.co/u/Pierre2)\
**Post date:** [October 8, 2018, 1:45pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/1 "2018-10-08T13:45:20Z")

</div>

Hello, I want to use the file output. The problem is that my String that I want to write in the output file contains quotes and double quote. I want to write this line :

> {"script": {"source": "ctx.\_source['Categorie SVI'] = '%{Categorie SVI}'","lang": "painless"},"query": {"term": {"ID Appel SVI.keyword": "%{ID Appel SVI}"}}}

There is my configuration :

> file {  
> path =\> "C:\Users\rtert\Documents\Elasticsearch/sortieSVI.txt"  
> codec =\> line { format =\> '{"script": {"source": "ctx.\_source['Categorie SVI'] = '%{Categorie SVI}'","lang": "painless"},"query": {"term": {"ID Appel SVI.keyword": "%{ID Appel SVI}"}}}'}  
> }

I think problem is that when logstash meet the first simple quote before Categorie SVI it think that it is the end of my string.

YOu can see that with my text editor.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f61dddd43ca247d400ed51260e7f01fc4db8f0ad.png)

---

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 8, 2018, 3:44pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/2 "2018-10-08T15:44:56Z")

</div>

Have you tried to escape quotes ?

Like this :

```
file {
path => "C:\Users\rtert\Documents\ElasticSearch/sortieSVI.txt"
codec => line { format =&gt; '{"script": {"source": "ctx._source[\'Categorie SVI\'] = \'%{Categorie SVI}\'","lang": "painless"},"query": {"term": {"ID Appel SVI.keyword": "%{ID Appel SVI}"}}}'}
}
```

---

<div class="post-metadata">

**Author:** ![Pierre2](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pierre2](https://discuss.elastic.co/u/Pierre2)\
**Post date:** [October 9, 2018, 6:46am UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/3 "2018-10-09T06:46:41Z")

</div>

Hello,  
Thank you for your answer but if I try your proposal I got this error :

![Capture](https://us1.discourse-cdn.com/elastic/original/3X/f/a/fa4ca020baec040ebd011998e9cebda8e0f41a9f.jpeg)

I think it is because of the "&gt". I tried to remplace "&gt" by "\>" and the error disapeared but the result was not the good one. In the output file it was written " \ ' " instead of " ' ".

---

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 9, 2018, 1:23pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/4 "2018-10-09T13:23:53Z")

</div>

You can try to format your entries with the json\_encode filter :

```
filter {
  json_encode {
    add_field => { "categorie_svi_field" => "ctx._source['Categorie SVI'] = '%{Categorie SVI}'" }
  }
}

file {
  path => "C:\Users\rtert\Documents\ElasticSearch/sortieSVI.txt"
  codec => line {
    format => '{
      "script": {
        "source": "%{categorie_svi_field}",
        "lang": "painless"
      },
      "query": {
         "term": { "ID Appel SVI.keyword" : "%{ID Appel SVI}" }
      }
    }'
  }
}
```

---

<div class="post-metadata">

**Author:** ![Pierre2](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pierre2](https://discuss.elastic.co/u/Pierre2)\
**Post date:** [October 9, 2018, 1:59pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/5 "2018-10-09T13:59:00Z")

</div>

Hi,

I don't have the json\_encode plugin installed so I tried with a basic  
mutate  
{  
add\_field....  
}

and it works !

Thank you.

---

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 9, 2018, 3:00pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/6 "2018-10-09T15:00:56Z")

</div>

Happy to have been able to help, I'm a novice too 😉

---

<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:** [November 6, 2018, 3:07pm UTC](https://discuss.elastic.co/t/how-to-write-quotes-and-double-quotes-in-the-same-string/151465/7 "2018-11-06T15:07:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
