Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function convertDottedKeyToObject(name, value) {
return name.split('.').reverse().reduce((acc, key) => ({ [key]: acc }), value);
}
JSON.stringify(convertDottedKeyToObject('it.is.a', 'one liner'), null, 2)
"{
"it": {
"is": {
"a": "one liner"
}
}
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment