Skip to main content
JSON nested (.json)
Nick Ustinov avatar
Written by Nick Ustinov
Updated over 4 months ago

JSON (JavaScript Object Notation) nested files are used for managing more complex localization structures in various applications.

Unlike flat JSON files, nested JSON files can contain objects within objects, allowing for a deeper hierarchical organization of translation strings. Lokalise supports nested JSON files with unlimited depth, enabling efficient management of intricate localization data.

Technical information

Overview

Format name:
JSON Nested

File extensions:
.json

Common use cases:
Managing and organizing localization strings in web and mobile applications that require hierarchical or nested structures.

Technical details:

  • Structure: Nested JSON files consist of key-value pairs, where values can be strings, numbers, arrays, or objects. This allows for complex, hierarchical data structures.

  • Encoding: UTF-8

File structure

Here's an example of a typical nested JSON file used for localization:

{
"main": {
"username": "User name",
"password": "Enter password",
"app": "Lokalise"
}
}

Separator:

Double colon (::) is used as a separator for nested JSON arrays. When adding a new key via the web interface, use :: to refer to JSON levels, for example main::username.

Force object type:
The triple colon (:::) is used as a force object type for the resulting JSON.

Examples with arrays

Here's an example JSON with an array:

{
  "main": [
    "Item 1",
    "Item 2",
    "Item 3"
  ]
}

The names of the created keys will be:

main::0
main::1
main::2


At export time:

  • These keys will be exported back as an array if all the sequential keys are present.

  • If the keys follow a sequential pattern with :: and one key corresponds to position 0, they will still be exported as an array, and the missing positions will be filled with empty strings. For example, if main::1 is deleted, and only main::0 and main::2 are present:

{
"main": [
"Item 1",
"",
"Item 3"
]
}
  • If the key corresponding to position 0 in the sequence is missing, the rest of the keys will be turned into an object, using the position number as the key name. For example, if main::0 is deleted, and only main::1 and main::2 are present:

{
    "main": {
        "1": "Item 2",
        "2": "Item 3"
    }
}

Example with an object

Here's an example of keys with triple colon (:::) in their names:

main:::0
main:::1
main:::2

The resulting JSON is always exported as an object, regardless of those keys containing a number sequence:

{
    "main": {
        "0": "Item 1",
        "1": "Item 2",
        "2": "Item 3"
    }
}

TypeScript Integration

If you are using TypeScript and want to add an autocompletion feature for your key names, you can add the following line of code to your app:

keyof typeof import ('./path/to/some/json/file.json')

Using with Lokalise

Lokalise supports nested JSON files, allowing you to manage and translate your hierarchical localization strings efficiently.

Supported project types

Please note that JSON files can be uploaded only to Web and mobile projects.

Additional reading

Did this answer your question?