# Trying to import JSON fails

**URL:** <https://discuss.elastic.co/t/trying-to-import-json-fails/193200>\
**Category:** Elasticsearch\
**Created:** [July 31, 2019, 6:16pm UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200 "2019-07-31T18:16:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticHT](https://avatars.discourse-cdn.com/v4/letter/e/9de0a6/32.png) [@elasticHT](https://discuss.elastic.co/u/elasticHT)\
**Post date:** [July 31, 2019, 6:16pm UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200/1 "2019-07-31T18:16:32Z")

</div>

I'm simply trying to get some data into ES to experiment with.

My JSON looks like this (randomly generated names):

```
{
"RECORDS":[
{
"fname":"Hyon",
"last":"Washko",
"addr":"18 Ratliff",
"City":"Cabot",
"State":"MN"
},
{
"fname":"Margie",
"last":"Dragovich",
"addr":"5 Liles Cp",
"City":"Idaho Fall",
"State":"NY"
},

```

]  
}

* * *

Now, I named the file "names.json" on my Desktop folder and tried this command:

**$ curl -H "Content-Type: application/json" [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) --data-binary @"/Users/me/Desktop/names.json"**

--

**Yet, I get this error:**

{"error":{"root\_cause":[{"type":"json\_e\_o\_f\_exception","reason":"Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 3]"}],"type":"json\_e\_o\_f\_exception","reason":"Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 3]"},"status":500}

* * *

Baffled how to just get some data into JSON.

Can anyone tell me what's wrong with the import above?

Thanks.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 2, 2019, 2:20pm UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200/2 "2019-08-02T14:20:34Z")

</div>

You need to prefix every json document in bulk with an index command and specify index name either in the index command or on URL

names.json:

```auto
{"index": {}}
{"fname":"Hyon", "last":"Washko","addr":"18 Ratliff", "City":"Cabot","State":"MN"}
{"index": {}}
{"fname":"Margie","last":"Dragovich","addr":"5 Liles Cp","City":"Idaho Fall","State":"NY"}

```

Command:

```auto
$ curl -XPOST "http://localhost:9200/test/_doc/_bulk" -H 'Content-Type: application/json' --data-binary @"/Users/me/Desktop/names.json"

```

---

<div class="post-metadata">

**Author:** ![elasticHT](https://avatars.discourse-cdn.com/v4/letter/e/9de0a6/32.png) [@elasticHT](https://discuss.elastic.co/u/elasticHT)\
**Post date:** [August 3, 2019, 10:06am UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200/3 "2019-08-03T10:06:44Z")

</div>

Thanks very much for your reply.

So, it sounds like I need to pre-process the JSON file programmatically to get it into the correct format.

Appreciate your note.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 5, 2019, 1:50pm UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200/4 "2019-08-05T13:50:36Z")

</div>

> [@elasticHT](#):
>
> pre-process the JSON file programmatically

Yes. You can use logstash with [json codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html) to do that.

---

<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:** [September 2, 2019, 1:50pm UTC](https://discuss.elastic.co/t/trying-to-import-json-fails/193200/5 "2019-09-02T13:50:41Z")

</div>

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