0

Hi i have a dummy JSON data file which i need to use in the JS of my LWC file can someone help me out for this...no sure how to do it,,,kindly help me out

Below is the Code :

{
    "copenStatus": [
        {
            "CDATE": "07/07/2020",
            "LDATE": "07/09/2020",
            "Acciuy #": "jngg",
            "Myweyru": "hggfhfb",
            
        },
        {
            "CDATE": "07/07/2020",
            "LDATE": "07/09/2020",
            "Acciuy #": "jngg",
            "Myweyru": "hggfhfb",
            
        },
        {
            "CDATE": "07/07/2020",
            "LDATE": "07/09/2020",
            "Acciuy #": "jngg",
            "Myweyru": "hggfhfb",
            
        }
    ]
}

JS :

import { LightningElement, track, api } from 'lwc';


export default class testjson extends LightningElement {

}

HTml

<template>
    
</template>

kindly help me out for this!!

4
  • Does this answer your question? displaying data from dummy JSON file in LWC Commented Aug 31, 2020 at 13:14
  • can you please just format my JSON i am not able to
    – Ria
    Commented Aug 31, 2020 at 13:25
  • I think its already well-formatted. Commented Aug 31, 2020 at 13:37
  • after using link you have given i am getting error as "Expected a JSON object, array or literal.json"
    – Ria
    Commented Aug 31, 2020 at 13:44

1 Answer 1

0

Use JSON.parse() to convert the json to object. Note that your JSON file has multiple extra commas which I removed and minified it.

import { LightningElement, track, api } from 'lwc';


export default class testjson extends LightningElement {
    property = JSON.parse(`{"copenStatus":[{"CDATE":"07/07/2020","LDATE":"07/09/2020","Acciuy #":"jngg","Myweyru":"hggfhfb"},{"CDATE":"07/07/2020","LDATE":"07/09/2020","Acciuy #":"jngg","Myweyru":"hggfhfb"},{"CDATE":"07/07/2020","LDATE":"07/09/2020","Acciuy #":"jngg","Myweyru":"hggfhfb"}]}`);

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .