It's recursive. An array inside a map inside a map, etc. You need a context-free grammar to parse it.
But this can be fixed. See how.
1. You can convert array into a map, right?
s"[[$i]]" -> arrayValue(i)
So, generally speaking, can have just maps.
2. If we ban (or escape) dots (
'.'
) inside keys, we can "flatten" the map of maps of maps, just by merging keys.
{"a" -> {
"key1" -> {
"[[0]]" -> "value at a.key1[0]"
...
}
}
}
will be
{"a.key1.[[0]]" -> "value at a.key1[0]"
...
}
3. We ban or escape quotes in keys, and html-escape quotes in values,
s/"\""/"""/g
, we can get rid of quotes in keys and have only delimiting quotes in values.
What does it give us? We get
Regular Language. That easy.
What's the point of having a regular language? Tons of them.
- You can keep it in SQL and match using regular SQL statements.
- You can check or extract data in shell scripts.
- You can parse it efficiently in your code, no need for parsers/combinators.
P.S. And fuck Crockford, he's an ignorant asshole anyway.