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
asked Dec 1, 2022 at 22:13
JavaSheriff
7,76126 gold badges102 silver badges178 bronze badges
2 Answers 2
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
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
default