Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSON Object to typescript class in react

I am working on converting the JSON to typescript interface and unbale to map the same.

I have the below format JSON string

{
  "abc": [
    {"key": "a", "value": "a"},
    {"key": "b", "value": "b"},
    {"key": "c", "value": "c"}
  ],
  "cdf": [
    {"key": "a", "value": "a"},
    {"key": "b", "value": "b"},
    {"key": "c", "value": "c"}
  ] 
}

I would like to define the class for it in the react but facing issues. Could any one please help to declare the typescript class for the above JSON.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks in advance

>Solution :


type Inner = {key: string, value: string}

type Thing = {
    abc: Inner[],
    cdf: Inner[]
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading