# Nest a json object from csv

**URL:** <https://discuss.elastic.co/t/nest-a-json-object-from-csv/73361>\
**Category:** Logstash\
**Created:** [January 31, 2017, 12:30pm UTC](https://discuss.elastic.co/t/nest-a-json-object-from-csv/73361 "2017-01-31T12:30:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Harper](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@Dan\_Harper](https://discuss.elastic.co/u/Dan_Harper)\
**Post date:** [January 31, 2017, 12:30pm UTC](https://discuss.elastic.co/t/nest-a-json-object-from-csv/73361/1 "2017-01-31T12:30:12Z")

</div>

I have a csv which has a field called cart in it and although I can import correctly the cart field creates new fields in relation to the nested products inside the cart rather just a single cart field.

> 431|  
> 2017-01-26 10:08:57|  
> example@example.com|  
> firstName|  
> lastName|  
> GBP|  
> GB|  
> 2015-06-14 07:16:39|  
> 43.88|  
> 2017-01-24 13:45:28|  
> f|  
> {"18272":{"19208":"1","19210":"1"},"18218":{"19099":"1"},"18783":{"19249":"2"}}|  
> 5|  
> GBP

The cart field looks like this where the top level number is the product ID and the second number is the variant ID and the third number is the qty in the cart.

> {  
> "18272":  
> {  
> "19208":"1",  
> "19210":"1"  
> },  
> "18218":  
> {  
> "19099":"1"  
> },  
> "18783":  
> {  
> "19249":"2"  
> }  
> }

Using the config I have I get fields in elastic that look like this cart.18272.19208 when I need a single field called cart that includes all the products and variants

This is my config file.

```
input {
  file {
    path => "/etc/logstash/files/*.csv"
    start_position => "beginning"
  }
}
filter {
  csv {
      columns => ['userId', 'profileUpdated', 'email', 'lastName', 'firstName', 'userCurrency', 'billingCountry', 'registeredDate', 'cartValue', 'cartUpdated', 'kitInCart', 'cart', 'itemsInCart' ,'cartCurrency']
      separator => "|"
      quote_char => "'"
  }
  date {
    match => ["registeredDate", "YYYY-MM-dd HH:mm:ss"]
  }
  json {
    source => "cart"
    target => "cart"
  }
}
output {
  stdout {
    codec => rubydebug
  }
  elasticsearch {
     hosts => "elasticsearch:9200"
     index => "users"
  }
}

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 1, 2017, 8:41pm UTC](https://discuss.elastic.co/t/nest-a-json-object-from-csv/73361/2 "2017-02-01T20:41:05Z")

</div>

There's no out of the box filter for this; you'll have to use a ruby filter and write some Ruby code.

---

<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 1, 2017, 8:41pm UTC](https://discuss.elastic.co/t/nest-a-json-object-from-csv/73361/3 "2017-03-01T20:41:44Z")

</div>

Closed on March 1, 2017, 8:41pm UTC

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