parse

fun parse(expression: String): CatalogPath

Parses an expression such as $.items[*].sku or $["odd name"].

The same grammar app.oreshkov.rabosh.variant.VariantPath.parse accepts, with [*] in place of a numeric index. A numeric index is rejected rather than silently collapsed: $.items[0] means something this type cannot represent, and quietly widening it to $.items[*] would answer a question the caller did not ask.

A field name that is not [A-Za-z0-9_]+ requires the bracket form, and the example that matters is not an odd one. $.@type does not parse — the dot form takes an identifier — so a protobuf-JSON corpus, where @type is on every message, is written $["@type"] throughout. In Kotlin the readable spelling is a raw string:

CatalogPath.parse("""$["@type"]""")
CatalogPath.parse("""$.players[*]["@type"]""")

Inside the quotes a backslash escapes the next character literally, so $["a\nb"] is the three-character name anb and not a, newline, b. That is self-consistent and it is deliberately not RFC 9535 §2.7's escaping — see app.oreshkov.rabosh.variant.VariantPath.toNormalizedPath for the interchange spelling, which is the one to hand to something outside the engine.

Throws

with the offending position, for malformed input.