# Json\_parse\_exception - Unexpected character (''' (code 39)): was expecting double-quote to start field name

**URL:** <https://discuss.elastic.co/t/json-parse-exception-unexpected-character-code-39-was-expecting-double-quote-to-start-field-name/174284>\
**Category:** Elasticsearch\
**Created:** [March 28, 2019, 9:29am UTC](https://discuss.elastic.co/t/json-parse-exception-unexpected-character-code-39-was-expecting-double-quote-to-start-field-name/174284 "2019-03-28T09:29:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![waqashamid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waqashamid/32/41507_2.png) [@waqashamid](https://discuss.elastic.co/u/waqashamid)\
**Post date:** [March 28, 2019, 9:29am UTC](https://discuss.elastic.co/t/json-parse-exception-unexpected-character-code-39-was-expecting-double-quote-to-start-field-name/174284/1 "2019-03-28T09:29:19Z")

</div>

I have a curl request which is:

```auto
curl -XGET "http://localhost:9200/_search" -H 'Content-Type: application/json' -d' { "query": { "range": { "created": { "gte": "2016-01-01", "lte": "2018-01-01", "format": "yyyy-MM-dd" } } } }'

```

I need to translate this to a python request.  
I have tried something like:

```auto
 query = {
            "query": {
                "range": {
                    "created": {
                    "gte": start_date,
                    "lte": end_date,
                    "format": "yyyy-MM-dd"
                    }
                }
            }
        }

        response = requests.post(
            url=settings.ES_SERVER_URL + SEARCH_URL,
            headers={'Content-Type': 'application/json'},
            data=str(query),
        )

```

I get:

```auto
[
    "{\"error\":{\"root_cause\":[{\"type\":\"json_parse_exception\",\"reason\":\"Unexpected character (''' (code 39)): was expecting double-quot",
    "e to start field name\\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4c81d054; line: 1, column: 3]\"}],\"type",
    "\":\"json_parse_exception\",\"reason\":\"Unexpected character (''' (code 39)): was expecting double-quote to start field name\\n at [So",
    "urce: org.elasticsearch.transport.netty4.ByteBufStreamInput@4c81d054; line: 1, column: 3]\"},\"status\":500}"
]

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [April 8, 2019, 1:52am UTC](https://discuss.elastic.co/t/json-parse-exception-unexpected-character-code-39-was-expecting-double-quote-to-start-field-name/174284/2 "2019-04-08T01:52:25Z")

</div>

`str(query)` won't produce a valid JSON string. Try `json.dumps` from the [JSON lib](https://docs.python.org/3/library/json.html) instead.

---

<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:** [May 6, 2019, 2:05am UTC](https://discuss.elastic.co/t/json-parse-exception-unexpected-character-code-39-was-expecting-double-quote-to-start-field-name/174284/3 "2019-05-06T02:05:10Z")

</div>

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