- I’m collecting data from a Google Spreadsheet and converting it into a JSON object.
- I’m then sending this JSON object to an API call to a web service.
- The issue is, the web service is stupid and doesn’t accept specific JSON keys if their value is different than
true
. So if let’s say we have a JSON key calledenabled
, I must choose to either send{"enabled": true}
, or simply omit the keyenabled
.
I can imagine only 2 ways to do this:
- Like I did, create a pre-defined JSON object with all keys, then once it’s populated with all values - remove the keys that have empty values.
- Create the JSON object “on-the-fly” (not with pre-defined keys), which I’m not sure how to do and if it’s possible.