# Search Error Unexpected token ' in JSON at position N

**URL:** <https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692>\
**Category:** Kibana\
**Created:** [February 27, 2021, 2:51pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692 "2021-02-27T14:51:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chatim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatim/32/78696_2.png) [@chatim](https://discuss.elastic.co/u/chatim)\
**Post date:** [February 27, 2021, 2:51pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/1 "2021-02-27T14:51:30Z")

</div>

Hello  
I'm running an elasticsearch cluster with kibana in docker.  
when i'm trying to create a pie chart and use Terms aggregation i got this error :

```
Search Error
Unexpected token ' in JSON at position 433

```

same thing work fine using line chart or if i used filter aggregation instead of Terms in pie chart.

- elastisearch version : 7.11.0
- kibana version : 7.11.0

I have same deployment in local and I did not encounter this problem.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 1, 2021, 1:27pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/2 "2021-03-01T13:27:11Z")

</div>

That sounds an awful lot like a bug. Could you export the failing visualization you built and post the resulting file here? That will make it easier to debug what goes wrong here.

Are you using the "Advanced JSON" functionality?

---

<div class="post-metadata">

**Author:** ![chatim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatim/32/78696_2.png) [@chatim](https://discuss.elastic.co/u/chatim)\
**Post date:** [March 1, 2021, 1:47pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/3 "2021-03-01T13:47:36Z")

</div>

thanks for your reply,  
No I don't use **Advanced Json** functionality.  
here is the whole error message :

```
Search Error

```

Unexpected token ' in JSON at position 433

```auto
SyntaxError: Unexpected token ' in JSON at position 433
    at JSON.parse (<anonymous>)
    at fn (https://*kibana-url*/37897/bundles/plugin/visTypeVislib/visTypeVislib.plugin.js:1:31468)
    at ExpressionFunction.fn (https://*kibana-url*/37897/bundles/plugin/expressions/expressions.plugin.js:1:128388)
    at _callee2$ (https://*kibana-url*/37897/bundles/plugin/expressions/expressions.plugin.js:1:65573)
    at l (https://*kibana-url*/37897/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:321:968491)
    at Generator._invoke (https://*kibana-url*/37897/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:321:968244)
    at Generator.forEach.e.<computed> [as next] (https://*kibana-url*/37897/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:321:968848)
    at asyncGeneratorStep (https://*kibana-url*/37897/bundles/plugin/expressions/expressions.plugin.js:1:57468)
    at _next (https://*kibana-url*/37897/bundles/plugin/expressions/expressions.plugin.js:1:57779)
    at https://*kibana-url*/37897/bundles/plugin/expressions/expressions.plugin.js:1:57929

```

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 1, 2021, 2:22pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/4 "2021-03-01T14:22:51Z")

</div>

Can you please export the visualization and paste it here? You can do this by going to Management \> Saved objects : [Saved Objects | Kibana Guide [7.11] | Elastic](https://www.elastic.co/guide/en/kibana/current/managing-saved-objects.html#_export)

---

<div class="post-metadata">

**Author:** ![chatim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatim/32/78696_2.png) [@chatim](https://discuss.elastic.co/u/chatim)\
**Post date:** [March 1, 2021, 3:08pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/5 "2021-03-01T15:08:09Z")

</div>

Ok, this is what you ask

```auto
    {"attributes":{"fieldAttrs":"{\"Présence d'allergies\":{\"count\":2},\"0000000000000011\":{\"count\":1},\"_id\":{\"count\":1}}","fields":"[]","title":"data"},"id":"4c9f6790-750a-11eb-b3b3-035fd300da33","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-02-27T20:06:01.825Z","version":"Wzc5NTUsMl0="}
{"attributes":{"description":"Unexpected token ' in JSON at position 433","kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"},"title":"Error ","uiStateJSON":"{}","version":1,"visState":"{\"title\":\"Error \",\"type\":\"pie\",\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"params\":{},\"schema\":\"metric\"},{\"id\":\"2\",\"enabled\":true,\"type\":\"terms\",\"params\":{\"field\":\"Présence d'allergies.keyword\",\"orderBy\":\"1\",\"order\":\"desc\",\"size\":5,\"otherBucket\":false,\"otherBucketLabel\":\"Other\",\"missingBucket\":false,\"missingBucketLabel\":\"Missing\"},\"schema\":\"segment\"}],\"params\":{\"type\":\"pie\",\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"isDonut\":true,\"labels\":{\"show\":false,\"values\":true,\"last_level\":true,\"truncate\":100}}}"},"id":"c6b99f80-7a9d-11eb-b183-7b4b720dbafe","migrationVersion":{"visualization":"7.11.0"},"references":[{"id":"4c9f6790-750a-11eb-b3b3-035fd300da33","name":"kibanaSavedObjectMeta.searchSourceJSON.index","type":"index-pattern"}],"type":"visualization","updated_at":"2021-03-01T14:52:42.750Z","version":"WzEwODMxLDNd"}
{"exportedCount":2,"missingRefCount":0,"missingReferences":[]}

```

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 1, 2021, 5:08pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/6 "2021-03-01T17:08:09Z")

</div>

I see, the `'` in the field name is breaking it. I tested a bit and this problem seems to be isolated to the pie chart (metric chart for example works fine)

I opened an issue for this here: [Pie: Field names are not escaped in expression · Issue #93069 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/93069)

For now you should be able to use Lens instead - it also features a pie chart and as far as I can tell is not affected by this bug

---

<div class="post-metadata">

**Author:** ![chatim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatim/32/78696_2.png) [@chatim](https://discuss.elastic.co/u/chatim)\
**Post date:** [March 1, 2021, 5:24pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/7 "2021-03-01T17:24:00Z")

</div>

Thank you very much for your responsiveness. while waiting for a fix for pie chart, i will use lens, it works correctly.

---

<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:** [March 29, 2021, 5:24pm UTC](https://discuss.elastic.co/t/search-error-unexpected-token-in-json-at-position-n/265692/8 "2021-03-29T17:24:28Z")

</div>

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