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 – Rahul Gawale Aug 31 '20 at 13:14
  • can you please just format my JSON i am not able to – Ria Aug 31 '20 at 13:25
  • I think its already well-formatted. – Rahul Gawale Aug 31 '20 at 13:37
  • after using link you have given i am getting error as "Expected a JSON object, array or literal.json" – Ria Aug 31 '20 at 13:44
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"}]}`);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.