Open jrouly opened 1 month ago
I'd point out that the underlying Javascript JSON.stringify
quotes all keys, not just dotted keys. So I'm not sure if this is due to the underlying functionality or if this package is doing its own quotation.
> JSON.stringify({'a.pple': 'apple'})
'{"a.pple":"apple"}'
> JSON.stringify({'a': 'apple'})
'{"a":"apple"}'
Looks like it's these lines. Specifically, "a.pple"
doesn't match the string regex so it gets handed off to stringifyBasicString
which intentionally adds quotes.
That's frustrating. This doesn't seem like it's going to be configurable behavior downstream.
function stringifyKey (key) {
const keyStr = String(key)
if (/^[-A-Za-z0-9_]+$/.test(keyStr)) {
return keyStr
} else {
return stringifyBasicString(keyStr)
}
}
function stringifyBasicString (str) {
return '"' + escapeString(str).replace(/"/g, '\\"') + '"'
}
I'm not entirely sure why this behavior is as such:
but the quoted key
"a.pple"
breaks in several different downstream tools I'm using. the current issue isruff
parsingruff.toml
and complaining that["lint.per-file-ignores"]
is invalid, where[lint.per-file-ignores]
was expected.