How to assign a Json source from an interface

0
  

I'm trying to generate an interface from a Json file but this one   giving error, what would be the error in my code?

 export interface Compra {
        event: string;
        timestamp: number;
        custom_data: number;
        value: string;
        key: number;
    }




{"events":[{"event":"comprou-produto",
                "timestamp":"2017-09-22T13:52:24.2311892-30:00",
                "custom_data":[{"key":"product_name",
                                "value":"Pants"},
                        {"key":"transaction_id","value":"135154"},
                               {"key":"product_price","value":131}]},

               {"event":"comprou",
                "timestamp":"2016-09-22T13:57:31.2311892-03:00",
                "revenue":250,
                "custom_data":[{"key":"store_name","value":"Loja y"},{"key":"transaction_id","value":"3029384"}]},

               {"event":"comprou-produto","timestamp":"2016-09-22T13:57:33.2311892-03:00","custom_data":[{"key":"product_price","value":150},{"key":"transaction_id","value":"3216545"},{"key":"product_name","value":"Shirt"}]},

               {"event":"comprou-produto","timestamp":"2016-10-02T11:37:35.2300892-03:00","custom_data":[{"key":"transaction_id","value":"3409340"},{"key":"product_name","value":"Shoes"},{"key":"product_price","value":120}]},

               {"event":"comprou","timestamp":"2016-10-02T11:37:31.2300892-03:00","revenue":120,"custom_data":[{"key":"transaction_id","value":"32132131"},{"key":"store_name","value":"Loja x"}]}]}'insira o código aqui'
    
asked by anonymous 11.09.2018 / 19:09

1 answer

1

You need to declare two interfaces and use one within the other:

export interface Compra {
        event: string;
        timestamp: number;
        custom_data: CustomData[];
    }


export interface CustomData{
        value: string;
        key: number;
    }
    
12.09.2018 / 12:29