nestedtext
raw JSON → 3.8 verified Sat May 09 auth: no python
Human readable and writable data interchange format, similar to YAML but simpler. Current version 3.8, requires Python >=3.6. Development is active with regular releases.
pip install nestedtext Common errors
error nestedtext.errors.NestedTextError: line 1, column 1: expected mapping or indented block ↓
cause The input starts with a value that is not a key-value mapping (e.g., a scalar or list at top-level). NestedText expects a mapping at top level.
fix
Wrap the top-level value in a dummy key, or ensure the file starts with a key-value pair.
error nestedtext.errors.NestedTextError: line 1, column 1: invalid character: ':' ↓
cause Input contains a bare colon not part of a key-value pair, or the key is missing.
fix
Ensure each line with a colon has the format 'key: value' with a space after colon.
Warnings
gotcha NestedText does not support all JSON types: numbers are parsed as strings and booleans are not natively supported. Dumping Python int/float will produce strings like '42' or '3.14'. ↓
fix Use explicit type conversion on load: int(value) to convert strings back to numbers. For booleans, use 'true'/'false' strings and map yourself.
gotcha The format is case-sensitive and strict about indentation. Mixing tabs and spaces or using inconsistent indentation will cause a parse error. ↓
fix Always use spaces (2 or 4) consistently. Avoid tabs.
Imports
- dumps wrong
import nestedtext; nestedtext.dumps()correctfrom nestedtext import dumps - loads wrong
import nestedtext; nestedtext.loads()correctfrom nestedtext import loads
Quickstart
from nestedtext import dumps, loads
data = {"name": "Alice", "age": 30, "pets": ["cat", "dog"]}
nt_string = dumps(data)
print(nt_string)
# Output:
# name: Alice
# age: 30
# pets:
# - cat
# - dog
loaded = loads(nt_string)
print(loaded)
# {'name': 'Alice', 'age': 30, 'pets': ['cat', 'dog']}