skip to Main Content

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

2

Answers


  1. 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'
            },
          ]
        }
      ]
    }
    
    
    
    Login or Signup to reply.
  2. I’m not totally sure what you mean by identifier unless you mean via javascript 👇

    var a = {
        "Printer":[    
        {
        "identifier" : "A0010",
        "reason" : "Not printing"
        },    
        {
        "identifier" : "A0020",
        "reason" : "Out of ink"
        },
        {
        "identifier" : "A0030",
        "reason" : "No power"
        },
        {
        "identifier" : "A0040",
        "reason" : "Noise"
        },
        {
        "identifier" : "A0300",
        "reason" : "Feedback"
        },
        {
        "identifier" : "A0500",
        "reason" : "Other"
        }]
    }
    var b = {
        "PC Issues":[    
        {
        "identifier" : "B0010",
        "reason" : "No power"
        },    
        {
        "identifier" : "B0020",
        "reason" : "BSOD"
        },
        {
        "identifier" : "B0030",
        "reason" : "Virus related"
        },
        {
        "identifier" : "B0300",
        "reason" : "Feedback"
        },
        {
        "identifier" : "B0500",
        "reason" : "Other"
        }]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search