0

Here is my json file

{
        id: '81224112234234222223422229',
        type: 'message',
        message: 'vacation',
        attachments: [
            {
                type: 'template',
                elements: [
                    {
                        id: '123123123123123',
                        title: 'job',
                        text: 'job',
                        properties: {
                            code: 'IO002',
                            value: 'messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003'
                        }
                    },
                    {
                        id: '123123123123123',
                        title: 'Date',
                        text: 'date',
                        properties: {
                            code: '2017-11-09~2017-11-09',
                            value: '2017-11-09~2017-11-09'
                        }
                    },
                    {
                        id: '123123123123123',
                        title: 'Sequence',
                        text: 'sequence',
                        properties: {
                            code: '1',
                            value: '1process/1,2process/1,3process/1'
                        }
                    }
                ]
            }
        ],
        module: 'temp'
}

i am using react.js and i want to extract all properties

result

job code: I0002
job value:messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003

date code:2017-11-09~2017-11-09
date value:2017-11-09~2017-11-09

sequence code:1
sequence value:1process/1,2process/1,3process/1

i tried to execute like this

const job=elements.filter(x=>x.text==='job');
const date=elements.filter(x=>x.text==='date');
const sequence=elements.filter(x=>x.text==='sequence');

is it proper way to use filter or another way to extract data from json file? i am new to react.js and es6,javascript.so i have no idea to display each property. how can i solve my problem? pz give me a tip.i want to extract properties

james
  • 235
  • 2
  • 5
  • 11
  • it seems to me that the data is not located on the first level but rather on the `attachment` property of your root object, as such you would have to adjust your filter to match that scenario – Icepickle Nov 07 '17 at 10:36
  • Possible Duplicate of https://stackoverflow.com/questions/41374572/how-to-render-an-array-of-objects-in-react-using-map-function/41374730#41374730 – Shubham Khatri Nov 07 '17 at 11:09

1 Answers1

0

You can use

var yourobject=JSON.parse(jsondata);
const job=yourobject.job;