Why does my namespace contain an array with a lot of null items?
If you see arrays filled with null values in your published JSON, it’s usually because of how Locize unflattens keys with numeric parts. By default, numeric key segments are interpreted as array indices.
Why Does This Happen?
Example: Numeric Keys Become Arrays
{
"colors.title": "Colors",
"colors.enum.0": "red",
"colors.enum.1": "green",
"colors.enum.2": "blue"
}This will be published as:
{
"colors": {
"title": "Colors",
"enum": [
"red",
"green",
"blue"
]
}
}Problem: Large Numeric Keys
If you use large numbers as keys (e.g. error codes), you may get arrays with many null items:
{
"error.title": "Errors",
"error.message.400": "Bad request",
"error.message.401": "Not authorized",
"error.message.404": "Not found"
}This will be published as:
{
"error": {
"title": "Errors",
"message": [
null, null, null, ... , "Bad request", "Not authorized", "Not found"
]
}
}How to Avoid Null Arrays
- Use non-numeric keys to force an object instead of an array:
{
"error.title": "Errors",
"error.message.unknown": "Unknown error",
"error.message.400": "Bad request",
"error.message.401": "Not authorized",
"error.message.404": "Not found"
}This will be published as:
{
"error": {
"title": "Errors",
"message": {
"unknown": "Unknown error",
"400": "Bad request",
"401": "Not authorized",
"404": "Not found"
}
}
}Best Practices
- Avoid mixing nested and flat key formats
- Prefer string keys for objects, especially when using large numbers
- Review your publish format settings (see how to change it)
Example: Mixing Formats
{
"my.3.paragraph": {
"someNested": "key"
}
}In flat format:
{
"my.3.paragraph.someNested": "key"
}In nested format:
{
"my": [
null, null, null,
{ "paragraph": { "someNested": "key" } }
]
}