Skip to content

Instantly share code, notes, and snippets.

@sondt2709
Last active May 7, 2021 09:06
Show Gist options
  • Save sondt2709/787e62e32ccd040249054192d711cb3a to your computer and use it in GitHub Desktop.
Save sondt2709/787e62e32ccd040249054192d711cb3a to your computer and use it in GitHub Desktop.
Parse JSON key-value to JSON object using Lodash
const json = {
'key1': 'value1',
'key2': 'value2',
}
const lodash = require('lodash')
const result = lodash.reduce(json, (obj, v, k) => {
obj[k] = {
message: v,
description: k,
}
return obj
}, {})
console.log(JSON.stringify(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment