I am working through an online tutorial that makes use of the Whitehouse Petitions JSON feed. I am using Swift 5 and have implemented my structs to conform to Codable. The Whitehouse JSON causes a Codable error. Below is a snippet of the JSON. The part that is causing trouble is "response". In the first example it is shown like I would expect an empty array to be, but when it has a value as in the second example, the JSON switches from [] to {} as shown below.
[ ] example:
"results":[
{
"id":"2722358",
"type":"petition",
"title":"Remove Chuck Schumer and Nancy Pelosi from office",
"body":"Schumer and Pelosi's hatred and refusing to work with...",
"petition_type":[
{
"id":291,
"name":"Call on Congress to act on an issue"
}
],
"signatureThreshold":100000,
"status":"closed",
"response":[
],
"created":1547050064,
"isSignable":false,
"isPublic":true,
"reachedPublic":0
},
{ } Example
"results":[
{
"id":"2722358",
"type":"petition",
"title":"Remove Chuck Schumer and Nancy Pelosi from office",
"body":"Schumer and Pelosi's hatred and refusing to work with...",
"petition_type":[
{
"id":291,
"name":"Call on Congress to act on an issue"
}
],
"signatureThreshold":100000,
"status":"closed",
"response":{
"id":2630367,
"url":"https://petitions.whitehouse.gov/response/response-your-petition-3",
},
"created":1547050064,
"isSignable":false,
"isPublic":true,
"reachedPublic":0
},
From what I can tell from my research of the issue, JSON should be written consistently. In other words, since "response" is never an array, but just a single value then it should have been written as { } instead of [ ] when empty. Is my understanding of this correct?