Home > Net >  Array of objects nested in an Array of objects
Array of objects nested in an Array of objects

Time:12-02

What is the correct way to represent this structure in JSON
Its Array of strings, with identifiers (A is identifier Printer is the array item)
then there is nested list of strings, with identifiers

A Printer   
    A0010 Not printing
    A0020 Out of ink
    A0030 No power
    A0040 Noise
    A0300 Feedback
    A0500 Other
B PC Issues
    B0010 No power
    B0020 BSOD
    B0030 Virus related
    B0300 Feedback
    B0500 Other

Thank you for your help

CodePudding user response:

Does this work making it easy for you to filter for things?

you can use Object.keys to find the corresponding message

const json = {
  data: [{
      identifier: 'A',
      itemType: 'Printer',
      error: [
        {
          'A0010': 'Not printing'
        },
        {
          'A0020': 'Out of ink'
        },
        {
          'A0030': 'No power',
        },
        {
          'A0040': 'Noise',
        },
        {
          'A0300': 'Feedback',
        },
        {
          'A0500': 'Other'
        }

      ]
    },
    {
      identifier: 'B',
      itemType: 'PC Issues',
      error: [
        {
          'B0010': 'No power'
        },
        {
          'B0020': 'BSOD',
        },
        {
          'B0030': 'Virus related'
        }, {
          'B0300': 'Feedback'
        },
        {
          'B0500': 'Other'
        },
      ]
    }
  ]
}


CodePudding user response:

I'm not totally sure what you mean by identifier unless you mean via javascript

  •  Tags:  
  • json
  • Related