# Parsing dictionary to Streamlit component

**URL:** <https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213>\
**Category:** Custom Components\
**Created:** [November 17, 2021, 5:58pm UTC](https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213 "2021-11-17T17:58:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coderdoufu](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/coderdoufu/32/11063_2.png) [@coderdoufu](https://discuss.streamlit.io/u/coderdoufu)\
**Post date:** [November 17, 2021, 5:58pm UTC](https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213/1 "2021-11-17T17:58:22Z")

</div>

I am trying to build my own custom component using React. I am not very familiar with React framework so I might need a little help here. I have also tried my best to search online but to no avail.

So I have a dictionary from my python file:

```auto
dic = {'key1':['value1_1','value1_2'], 
       'key2':['value2_1','value2_2'],}

```

and I want to parse this to the frontend and render two forms with radio button labeled with the list (eg. value1\_1, value1\_2 for first form)

I am using material ui and here is the code I run into problem:

```
    {Object.entries(myObject).map(([key,values])=>(
      <FormControl component="fieldset">
        <FormLabel component="legend">Gender</FormLabel>
        <RadioGroup
          aria-label="gender"
          defaultValue="female"
          name={key}
        >
          {Object.entries(values).map(val => {
            return <FormControlLabel value={val.toString()} control={<Radio />} label={val.toString()} />
          })}
        </RadioGroup>
      </FormControl>
    ))}

```

Here is the returned error:

Overload 1 of 2, ‘(o: { [s: string]: unknown; } | ArrayLike): [string, unknown]’, gave the following error.  
Argument of type ‘unknown’ is not assignable to parameter of type ‘{ [s: string]: unknown; } | ArrayLike’.  
Type ‘unknown’ is not assignable to type ‘ArrayLike’.  
Overload 2 of 2, ‘(o: {}): [string, any]’, gave the following error.  
Argument of type ‘unknown’ is not assignable to parameter of type ‘{}’. TS2769

Hope to get some help here! Thanks so much in advance.

---

<div class="post-metadata">

**Author:** ![asehmi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/asehmi/32/1771_2.png) [@asehmi](https://discuss.streamlit.io/u/asehmi)\
**Post date:** [November 18, 2021, 2:31am UTC](https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213/2 "2021-11-18T02:31:17Z")

</div>

This is where you crack open the browser dev tools and debug the structure and type of myObject. You should also console.log it. Make sure you’re not sending it as a json string from python to javascript, but as a json-serializable object. That way, it’ll be more naturally deserializable in the front end.

HTH.

---

<div class="post-metadata">

**Author:** ![coderdoufu](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/coderdoufu/32/11063_2.png) [@coderdoufu](https://discuss.streamlit.io/u/coderdoufu)\
**Post date:** [November 18, 2021, 1:44pm UTC](https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213/3 "2021-11-18T13:44:13Z")

</div>

Hi,

Thanks so much for your reply. I think I have found the solution.

```auto
{Object.keys(greet).map((key)=>(
  <FormControl component="fieldset">
    <FormLabel component="legend">Gender</FormLabel>
    <RadioGroup
      aria-label="gender"
      defaultValue="female"
      name={key}
    >
      {greet[key] && greet[key].map((i:string)=>
        <FormControlLabel value={i} control={<Radio />} label={i}></FormControlLabel>
      )}
    </RadioGroup>
  </FormControl>
))}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [November 18, 2022, 1:44pm UTC](https://discuss.streamlit.io/t/parsing-dictionary-to-streamlit-component/19213/4 "2022-11-18T13:44:25Z")

</div>

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