Last active
May 7, 2021 09:06
-
-
Save sondt2709/787e62e32ccd040249054192d711cb3a to your computer and use it in GitHub Desktop.
Parse JSON key-value to JSON object using Lodash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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