"location" : null // this is not really an array it's a null object
"location" : []   // this is an empty array

It looks like this API returns null when there is no location defined - instead of returning an empty array, not too unusual really - but they should tell you if they're going to do this.

Answer from Matt Varblow on Stack Overflow
Discussions

What to return if a collection is empty?
What should be returned when an empty collection is queried? a hash with an empty array? example 1 GET /photos HTTP/1.1 200 OK Content-Type: application/json { "photos": [] } example 2 GE... More on github.com
🌐 github.com
14
May 27, 2013
How to assert json with empty array
The following paste contains data returned by our API. { "result": "OK", "sysStatisticsReport": null, "sysStatisticsData": { "sysDataStatisticsList": [{ "RLibID":"x400410000", "sysDataDetails": [] }, { "RLibID":"x872690000", "sysDataDetails": [] }, { "RLibID":"x871710000", "sysDataDetails": ... More on community.postman.com
🌐 community.postman.com
0
0
June 29, 2020
Best Practices to send for Empty Values of a JSON API?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
16
16
April 22, 2024
An empty array in JSON configuration file results in a null value in the configuration object
The keys from option 1 and 3 could also just always be present if the key path was present in JSON, even if it isn't an empty array. So then the corresponding keys could be added. For example, a value of `[ "One", "Two" ] would emit "SomeConfiguration:SomeArray:[]" = null, "SomeConfigurati... More on github.com
🌐 github.com
2
February 7, 2025
🌐
Laracasts
laracasts.com › discuss › channels › laravel › output-empty-arrays-and-objects-in-json
Output Empty Arrays and Objects in JSON
I'm developing an API and need to be able to output empty arrays and objects in the returned JSON. However, I'm running into a problem where empty objects/dicts are returned as empty arrays. Example Request Body: { "attributes": { "empty_array": [], "empty_object": {} } } Actual Response: { ...
🌐
GitHub
github.com › json-api › json-api › issues › 101
What to return if a collection is empty? · Issue #101 · json-api/json-api
May 27, 2013 - example 4: HTTP/1.1 200 OK Content-Type: application/json { "meta": { "client-ids": true } } I think a hash with an empty array is probably less likely to cause surprises and would be happy to provide a patch if you agree. Reactions are currently unavailable ·
Author: json-api
🌐
JSON for Modern C++
json.nlohmann.me › api › basic_json › empty
empty - JSON for Modern C++
#include <iostream> #include ... = 23.42; json j_object = {{"one", 1}, {"two", 2}}; json j_object_empty(json::value_t::object); json j_array = {1, 2, 4, 8, 16}; json j_array_empty(json::value_t::array); json j_string = "Hello, world"; // call empty() std::cout << ...
Find elsewhere
🌐
Postman
community.postman.com › help hub
How to assert json with empty array - Help Hub - Postman Community
The following paste contains data returned by our API. { "result": "OK", "sysStatisticsReport": null, "sysStatisticsData": { "sysDataStatisticsList": [{ "RLibID":"x400410000", …
Published: June 29, 2020
🌐
Reddit
reddit.com › r/learnprogramming › best practices to send for empty values of a json api?
r/learnprogramming on Reddit: Best Practices to send for Empty Values of a JSON API?
April 22, 2024 -

What do you choose? Getting lots of conflicting answers.

  1. Null

  2. Undefined (Omitted from JSON)

  3. Empty of that type?

    1. String = ""

    2. Number = 0

    3. Boolean = false

    4. Array = []

    5. Object = {}

CMS JSON API to be consumed by JS Framework Frontend

🌐
IBM
ibm.com › docs › en › baw › 19.0.0
Handling JSON null and empty arrays and objects
August 11, 2022 - Handling null and empty arrays and objects used in JSON data is described.
🌐
JSON FYI
jsonfyi.com › home › learn › json arrays — syntax, examples, and common mistakes
JSON arrays — syntax, examples, and common mistakes
April 27, 2026 - A JSON array is an ordered list of values wrapped in square brackets and separated by commas — for example ["a", "b", "c"]. Arrays are zero-indexed, may hold any mix of JSON types (strings, numbers, booleans, null, objects, or other arrays), may be empty ([]), and must not have a trailing comma after the last element.
🌐
JSON for Modern C++
json.nlohmann.me › api › basic_json › array
array - JSON for Modern C++
This function is only needed to ... (basic_json(initializer_list_t, bool, value_t)). These cases are: creating an array whose elements are all pairs whose first element is a string -- in this case, the initializer list constructor would create an object, taking the first elements as keys · creating an empty array -- passing the empty initializer list to the initializer list constructor yields an empty object ... The following code shows an example for the array ...
🌐
Medium
medium.com › swlh › arrays-and-json-in-go-98540f2fa74e
Handling Null JSON Arrays in Go. How to handle nil slices when encoding… | by Steven Nguyen | The Startup | Medium
July 12, 2020 - encoding/json: “nonil” struct tag to marshal nil slices and maps as non-null · But, as of this writing, these proposals have not been accepted. As such, in order to overcome the problem of null arrays, we have to set nil slices to empty slices.
🌐
Jitterbit
community.jitterbit.com › s › question › 0D54X00007NjTiLSAV
JB Customer
March 3, 2022 - Loading · ×Sorry to interrupt · Refresh
🌐
Medium
jyotishgher.medium.com › empty-jsonissue-in-json-request-e3ebbd79644e
Empty Array Issue in JSON Request | by www.jyotishgher.in | Medium
February 14, 2025 - The “empty array issue” in JSON requests usually refers to a situation where your server-side code (e.g., in PHP, Python, Node.js, etc.) is receiving an empty array ([]) in the request body when you expect it to contain data.
🌐
GitHub
github.com › dotnet › extensions › issues › 5858
An empty array in JSON configuration file results in a null value in the configuration object · Issue #5858 · dotnet/extensions
February 7, 2025 - So then the corresponding keys could be added. For example, a value of `[ "One", "Two" ] would emit "SomeConfiguration:SomeArray:[]" = null, "SomeConfiguration:SomeArray:0" = "One" and "SomeConfiguration:SomeArray:1" = "Two".
Author: dotnet
Top answer
1 of 2
6

If you want to have empty space in JSON, you should fill it with null.

Example:

var pattern = [ ["C5", 3], null, null, null, null, null, null, null, ["C5", 3], null, null, null, null, ...... ]
2 of 2
4

If you don't want to use null with a sparse array, you could use the object representation of an array.

 pattern = [["C5", 3], , , , , , , , ["C5", 3], , , ]

... would be replaced by an object with index value as properties and an additional length property:

parse_array = {
    0: ["C5", 3],
    8: ["C5", 3],
    length: 12
}

This object can be generated from the array using its reduce method:

parse_array = pattern.reduce( ( obj, val, i ) =>
  {
    obj.length++
    if ( val )
      obj[i] = val
    return obj
  }, { length: 0 } )

Then it's easy to convert the object into a JavaScript Array, using a simple arrow function:

pattern = Array.from( parse_array, v => v )

//Encode array

var pattern = [["C5",3],null,null,null,null,null,null,null,["C5",3],null,null,null]

out.innerHTML = JSON.stringify( pattern ) + "\n"

var parse1 = pattern.reduce( ( obj, val, i ) =>
  {
    obj.length++
    if ( val )
      obj[i] = val
    return obj
  }, { length } )

out.innerHTML += JSON.stringify( parse1 ) + "\n"


//Decode object

var parse2 = {
  0: ["C5", 3],
  8: ["C5", 3],
  length: 12
}

out.innerHTML += JSON.stringify( parse2 ) + "\n"

out.innerHTML += JSON.stringify( Array.from( parse2,  v => v ) )  + "\n"
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
  <title></title>
</head>
<body>
	<h3>JSON array with empty items</h3>
	<pre id="out"></pre>
</body>
</html>

🌐
GitHub
github.com › nlohmann › json › issues › 27
Creating an empty array · Issue #27 · nlohmann/json
January 13, 2015 - json customers; for (...) { customers.push_back(...) } cout << customers; However, if the for loop doesnt happen, I would like to return an empty array (eg []) Is they an other way to get this behaviour without doing json customers= json::parse("[]"); ? Reactions are currently unavailable ·
Author: nlohmann