# manipulating json

**URL:** <https://talk.observablehq.com/t/manipulating-json/6037>\
**Category:** Help\
**Created:** [January 6, 2022, 8:10am UTC](https://talk.observablehq.com/t/manipulating-json/6037 "2022-01-06T08:10:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/colin/32/5966_2.png) [@Colin](https://talk.observablehq.com/u/Colin)\
**Post date:** [January 6, 2022, 8:10am UTC](https://talk.observablehq.com/t/manipulating-json/6037/1 "2022-01-06T08:10:01Z")

</div>

Hello,  
I’m a brand new user of Observable (it sounds so fantastic! Thanks for such a great platform!).  
I have difficulty handling json according to my needs. I got lost with .nest .map etc.

I have a simple csv file. I load it into my notebook and the result below is displayed:

```auto
data = Array(x items) [
0: Object {header1: "value1", header2: "value2", header3: "value3", etc.}
1: Object {header1: "value1", header2: "value2", header3: "value3", etc.}
2: Object {header1: "value1", header2: "value2", header3: "value3", etc.}
...more
]

data = FileAttachment("mycsv.csv").csv()

```

I need to get a result like this:

```auto
jsonToDownload = Object {
value1: Object <!-- from data.object[0] => header1 --> {
        header2: "value2"
        header3: "value3"
        etc.
        }
value1: Object <!-- from data.object[1] => header1 --> {
        header2: "value2"
        header3: "value3"
        etc.
        }
value1: Object <!-- from data.object[2] => header1 --> {
        header2: "value2"
        header3: "value3"
        etc.
        }
...more
}

```

What’s the best way to do this?  
Thanks in advance for helping out!

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [January 6, 2022, 8:27am UTC](https://talk.observablehq.com/t/manipulating-json/6037/2 "2022-01-06T08:27:24Z")

</div>

try [Object.fromEntries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)?

`Object.fromEntries(data.map(d => [d.header1, d]))`

the only difference with your requirement is that this doesn’t remove header1 from the object. To do this, we need a bit more wrangling:

```auto
Object.fromEntries(
  data.map(d => [
    d.header1,
    Object.fromEntries(Object.entries(d).filter(([k]) => k !== "header1"))
  ])
)

```

---

<div class="post-metadata">

**Author:** ![Colin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/colin/32/5966_2.png) [@Colin](https://talk.observablehq.com/u/Colin)\
**Post date:** [January 6, 2022, 8:37am UTC](https://talk.observablehq.com/t/manipulating-json/6037/3 "2022-01-06T08:37:31Z")

</div>

🙏 it’s perfect! thank you very much
