0

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 2

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'
        },
      ]
    }
  ]
}


Sign up to request clarification or add additional context in comments.

Comments

0

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"
    }]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.