What's new
Carbonite

South Africa's Top Online Tech Classifieds!
Register a free account today to become a member! (No Under 18's)
Home of C.U.D.

JSON formatting rules - help please

iamgigglz

VIP
VIP Supporter
Rating - 100%
311   0   0
Joined
Aug 19, 2014
Messages
8,684
Reaction score
2,335
Points
10,155
Location
Parkhurst
Here's my current structure:

[CODE lang="json" title="My format"]{
"Showroom": {
"Address": "1 Car Lane",
"Owner": "Fred",
"Cars": [
{
"Make": "Ford",
"Model": "Figo"
},
{
"Make": "Renault",
"Model": "Duster"
}
]
}
}[/CODE]


This client I'm working for wants this:

[CODE lang="json" title="Their format" highlight="7, 11"]{
"Showroom": {
"Address": "1 Car Lane",
"Owner": "Fred",
"Cars": [
{
"Car":{
"Make": "Ford",
"Model": "Figo"
},
"Car":{
"Make": "Renault",
"Model": "Duster"
}
}
]
}
}[/CODE]

Note lines 7 and 11. They want each element in the array of cars to have the "car" tag. Is that valid JSON formatting?
 
Here's my current structure:

[CODE lang="json" title="My format"]{
"Showroom": {
"Address": "1 Car Lane",
"Owner": "Fred",
"Cars": [
{
"Make": "Ford",
"Model": "Figo"
},
{
"Make": "Renault",
"Model": "Duster"
}
]
}
}[/CODE]


This client I'm working for wants this:

[CODE lang="json" title="Their format" highlight="7, 11"]{
"Showroom": {
"Address": "1 Car Lane",
"Owner": "Fred",
"Cars": [
{
"Car":{
"Make": "Ford",
"Model": "Figo"
},
"Car":{
"Make": "Renault",
"Model": "Duster"
}
}
]
}
}[/CODE]

Note lines 7 and 11. They want each element in the array of cars to have the "car" tag. Is that valid JSON formatting?
According to The JSON Validator no. I belive it's valid in XML.
The JSON Validator is very useful
 
Short answer, No. Duplicate key.
Validate: The JSON Validator

Best I can think of their "correct" JSON is:

JSON:
{
  "Showroom": {
    "Address": "1 Car Lane",
    "Owner": "Fred",
    "Cars": [
      {
        "Car": {
          "Make": "Ford",
          "Model": "Figo"
        }
      },
      {
        "Car": {
          "Make": "Renault",
          "Model": "Duster"
        }
      }
    ]
  }
}
 
Yeah, I FREAKING thought so! Thank you.
The client I'm working with is HUGE so I gave their devs more credit than was due apparently.
 
Pointless to specify car within cars as nothing else should be in that set other than a cars.
Just more work for themselves, and confusing to work with.

If you want to loop through it you now have to specify:

for car in cars
car_make = car.car.make :ROFLMAO:

instead of:

for car in cars
car_make = car.make
 
Did you resolve this issue? Hit me a PM as I have been working with this for quite a while and I might be able to help…
 
I often see this when they write their own fomratters and not use standard ones ... esp in the php world ... also happens when they throw stuff over GET for the first time in their careers trying to use their own piece of clever code, and can not understand why the space in a varname is falling over ....
 
Late to the party and the question has already been answered. But adding a 2c comment on the fact that most devs these days couldn't code themselves out of the proverbial brown paper bag.

I've oftentimes thought that I was at fault rather than the big team of Devs only to find that I wasn't the one smoking my socks.
 
This!
Pointless to specify car within cars as nothing else should be in that set other than a cars.
Just more work for themselves, and confusing to work with.

If you want to loop through it you now have to specify:

for car in cars
car_make = car.car.make :ROFLMAO:

instead of:

for car in cars
car_make = car.make

You want to un-abstract your dataset as much as possilbe so it is easier to maintain.
 

Users who are viewing this thread

Latest posts

Back
Top Bottom