# Ingest array of JSON objects

**URL:** <https://discuss.elastic.co/t/ingest-array-of-json-objects/222216>\
**Category:** Elasticsearch\
**Created:** [March 5, 2020, 7:21am UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216 "2020-03-05T07:21:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abregman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abregman/32/63862_2.png) [@abregman](https://discuss.elastic.co/u/abregman)\
**Post date:** [March 5, 2020, 7:21am UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/1 "2020-03-05T07:21:12Z")

</div>

Is it possible to import into elasticsearch an array of JSON objects?  
Something like this: [{'a': 1}, {'b': 2}, ...]

Right now I get this error when trying to do so: "Malformed action/metadata line [1], expected START\_OBJECT but found [START\_ARRAY]"

The command I'm using is: curl -H "Content-Type: application/json" -XPOST "localhost:9200/test/\_bulk?pretty&refresh" --data-binary "@test.json"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2020, 7:34am UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/2 "2020-03-05T07:34:31Z")

</div>

Welcome!

Only in one document like:

```
{
  "foo": [{'a': 1}, {'b': 2}, ...]
}

```

If your goal is to ingest multiple documents, have a look at the bulk API.

---

<div class="post-metadata">

**Author:** ![abregman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abregman/32/63862_2.png) [@abregman](https://discuss.elastic.co/u/abregman)\
**Post date:** [March 5, 2020, 12:12pm UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/3 "2020-03-05T12:12:47Z")

</div>

Thank you for the help.  
Are we talking about this? [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)

I'm not sure how exactly to use it to process every item in the array as a document. Is there an example that demonstrates this use case?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2020, 12:33pm UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/4 "2020-03-05T12:33:33Z")

</div>

There's no way to send your content as is without doing any transformation first.  
So use whatever language, script you want, split the array into individual documents, add a header for each and send it as a bulk request to the bulk API.

---

<div class="post-metadata">

**Author:** ![abregman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abregman/32/63862_2.png) [@abregman](https://discuss.elastic.co/u/abregman)\
**Post date:** [March 5, 2020, 12:35pm UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/5 "2020-03-05T12:35:20Z")

</div>

I see. Thanks again for the help 🙂

---

<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:** [April 2, 2020, 12:35pm UTC](https://discuss.elastic.co/t/ingest-array-of-json-objects/222216/6 "2020-04-02T12:35:20Z")

</div>

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