Universal JS like path parser for python
Specification
1. Overview
This specification defines how to reference properties or indices in a nested data structure using a combined notation:
- Dot notation segments: a.b.c
- Bracket notation segments: ["a"]["b"][0]
- Mixed notation: a["b"].c[0]
It also imposes constraints to avoid ambiguous or invalid dot notation:
- No leading dots (e.g., .something is invalid).
- No trailing dots (e.g., something. is invalid).
- No repeated consecutive dots (e.g., a..b is invalid).
2. Dot Notation Rules
- Valid Identifiers Only:
- Each dot-delimited token (segment) must be a valid identifier in the target environment.
- This typically means alphanumeric characters plus underscores (e.g., myKey, user2, some_value).
- No Leading Dot:
- A path cannot begin with a dot. For example, .a.b is invalid.
- No Trailing Dot:
- A path cannot end with a dot. For example, a.b. is invalid.
- No Consecutive Dots:
- A path cannot contain .. (two or more consecutive dots). For example, a..b is invalid.
Examples of valid pure dot paths:
- user.name.first
- accountDetails.balance
- config.version
Examples of invalid pure dot paths (under this specification):
- .leadingDot (leading dot)
- trailingDot. (trailing dot)
- double..dots (multiple consecutive dots)
3. Bracket Notation Rules
Bracket notation allows any valid string or number inside square brackets:
["some.key"] ["another space"] [42]
3.1 String Keys
- Must be enclosed in quotes inside the brackets: ["any string"] or ['any string'].
- Permits spaces, dots, dashes, or reserved characters in the key.
3.2 Numeric Indices
- To represent arrays or list indices, use bracket notation with a numeric literal: [0], [10], etc.
- No quotes needed for a pure integer.
3.3 Constraints on Brackets
- Bracket notation does not have the same dot-based restrictions (no worry about leading/trailing dots).
- However, mixing bracket notation into a dot path must still obey the dot-notation constraints for the dot-delimited segments.
4. Mixed Usage
When dot notation and bracket notation are combined, the path can jump between the two. Here are the rules:
- Dot notation segments must follow the dot rules (valid identifiers, no leading/trailing dots, no consecutive dots).
- Bracket segments can appear anywhere in the path, typically after a valid dot segment or another bracket segment.
- A path cannot be just a dot—there must be a valid segment or bracket after/before each dot.
Examples:
- a.b[0].c
- a and b are valid identifiers in dot notation, [0] is a bracket for an array index, then .c is back to dot notation.
- user["personal.info"].preferences["color.theme"]
- Dot segments: user, preferences
- Bracket segments: ["personal.info"], ["color.theme"]
5. Unified Path Grammar (Informal)
Here is a conceptual grammar that respects the stricter dot-notation constraints:
Path := DotSegment ( ('.' DotSegment) | BracketSegment )*
DotSegment := ValidIdentifier
BracketSegment := '[' ( StringLiteral | NumberLiteral ) ']'
ValidIdentifier := (Alpha | '') (AlphaNum | '' )* # No dots, no leading digit, no spaces, etc., based on your environment's definition.
StringLiteral := '"' '"' | "'" "'"
NumberLiteral := Digit+
- Path starts with a DotSegment (this disallows a leading dot).
- A . must always be followed by another DotSegment (disallowing empty segments or multiple consecutive dots).
- You can insert a BracketSegment at any point to handle special keys or numeric indices.
No leading/trailing dot is enforced by starting with DotSegment and only permitting subsequent '.' DotSegment pairs. No consecutive dots is enforced by requiring a segment name after each '.'.
6. Example Paths Under This Specification
-
Pure Dot Notation, All Valid
- employee.profile.name
- config.version.major
-
Mixed Dot & Bracket
- a.b[0].c
- root["user data"].info["age.range"][2]
-
All Bracket
- ["root"]["user data"]["something.with.dots"][42]
- Even though you can reference everything in brackets, if you switch to dot notation, any segment must be a valid identifier.
-
Invalid
- .leadingDot.segment (leading dot)
- segment. (trailing dot)
- a..b (multiple consecutive dots)
- root[""][""] is technically valid bracket usage for empty strings, but if you wanted empty string segments in dot notation, that’s disallowed here.
7. Traversal Semantics
Implementations using this path specification will:
- Parse the path into a sequence of segments (each being either a valid dot identifier or a bracketed key/index).
- Traverse the nested data structure in order:
- For a DotSegment ( DotSegment ): move to the sub-key DotSegment.
- For a BracketSegment ( [StringLiteral] ): move to the sub-key of that string.
- For a BracketSegment ( [NumberLiteral] ): move to the array index NumberLiteral.
- Stop once all segments have been resolved, returning the final value or indicating a missing path if any key/index does not exist.
8. Conclusion
This specification provides:
- Strict dot-notation compatibility (no leading/trailing/multiple consecutive dots).
- Flexible bracket notation to handle any string key (including spaces, symbols, or dots) or numeric index.
- Mixed usage that seamlessly allows dot segments for valid identifiers and bracket segments for anything else.
Metadata
Release files for dotdict-parser 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 259.4 kB
Release files / dotdict_parser-0.8.1-cp314-cp314t-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp314-cp314t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 23.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
0bdf4c443129f55d63d6ccf9d82aa90c201141f731a90b408b7a0cb2bd66206d
|
|
BLAKE2b-256 checksum How to use checksums |
d60920086e0af3c978fb1e80b748bef6207f0024bd028825088cb2f728fcf763
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 23.9 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
29139da2ef104fcbe68daf424521adfc82a23419fbf9ee2d455a0ed2374346e8
|
|
BLAKE2b-256 checksum How to use checksums |
b83b56d291e61ddfcbc0fcff09443b894424f07825e7968eb4fd2eabd411baa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 21.5 kB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
36c00519db5ff3f77831029dfa08be1cd6de7c7cc1283d7a4e08c0c60309f837
|
|
BLAKE2b-256 checksum How to use checksums |
56943317f1cc60c44c5367d11e3ba569cc54b9e5a1ec87e3d87580f797e15b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 21.6 kB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
82cdb6e9395c36f28f3051dfbae8a918b7e35ded1f894a9508f1bca5ff3ae83d
|
|
BLAKE2b-256 checksum How to use checksums |
d133a99712eeeafa148ce485a513d986051b7a0193f169e085a34616b2c7a9dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 21.4 kB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
d44d0cc27a9e67a1966dfbf204ba4cdccf3adf75ec2bc3cf932317a2c4109afd
|
|
BLAKE2b-256 checksum How to use checksums |
d71fab8ae94024a509dd76d72617b560103475f140d4c0fad088f8221baba610
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 21.6 kB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
556cbe7cbcc648b020991ecb05b55770511efd561dc0346a15e521b8a2cca905
|
|
BLAKE2b-256 checksum How to use checksums |
bb72b46922ee41924b35e6c73997ef4bc177ca1914f1d94f0b1c2befede9a589
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 21.4 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
f9ad2fef6d0548094bfe6548006d9c41032a2780d03783d96110c464233695a6
|
|
BLAKE2b-256 checksum How to use checksums |
61124f26ba0032c2429a6bdcf43e9bb625e8c937db39820401ab391bfde3cb95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 21.5 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
d19f028d763980e646814338a75a46982a1c83aafb12d28bfd3e198d8ed5f102
|
|
BLAKE2b-256 checksum How to use checksums |
45195a06905b69f9bbc7d0fcdfabb2b0292cc67e667ed539033ee3f2c4d19d73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 20.8 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
d250a8e4cbe5cdadae7d1b2cda6c1426e4b1c42199f04befc0ee416735b2e490
|
|
BLAKE2b-256 checksum How to use checksums |
c52222121a182f9db63a5b823b8011187ac459359c3eb8b29cc748701451f04c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 20.9 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
16650dc21f0348f004ced02565f83f9c8954a962a31f9a8dc4bca4458f63b836
|
|
BLAKE2b-256 checksum How to use checksums |
1850fb2394370661c5b2b5cf07ff272a9c6e1f10d3589fb1176996b1a59987ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 20.5 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
dca96608db6e8a089e5cd0318e1937e7fa5ec6ccafc29395572e40cf2b17b9e6
|
|
BLAKE2b-256 checksum How to use checksums |
0cf1dbcf0dd2b8ed745b0a9a3c208b5cf3c3b530a311cc88979e1b07ccedacae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dotdict_parser-0.8.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | dotdict_parser-0.8.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 20.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
942c58756f59b7d9ba634d3b6e9419d23f71e566bfb08fa2c84d02a5a6c1bd21
|
|
BLAKE2b-256 checksum How to use checksums |
2fba20c398b6a1f135eee7461fca45ab081442bf7806d47f5cdc3d931c2d3d3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|