JSON nested (.json)
Nick Ustinov avatar
Written by Nick Ustinov
Updated over a week ago

You might also be interested in checking out our JSON localization tutorial (aimed towards web devs).

In addition to flat JSON files, Lokalise supports nested JSON with unlimited depth:

{
  "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 JSON levels, for example main::username.

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

Examples with arrays

Let's import an example JSON with an array:

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

Here are the names of the created keys, with double colon (::):

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. This would be the export result if main::1 was deleted, and only main::0 and main::2 were present:

{
"main": [
"Item 1",
"",
"Item 3"
]
}
  • However, if the key corresponding to position 0 in the sequence is missing because it has been deleted, the rest of keys will be turned into an object, using the position number as the key name. Here is the export result when main::0 is deleted, and only main::1 and main::2 are present:

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

Example with an object

On the other hand, here is 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 those keys containing a number sequence:

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

If you are using TypeScript and want to add 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')
Did this answer your question?