Skip to content

Instantly share code, notes, and snippets.

@Dinir
Created January 16, 2023 09:35
Show Gist options
  • Save Dinir/3c1265b96e4253d197d323984d45115f to your computer and use it in GitHub Desktop.
Save Dinir/3c1265b96e4253d197d323984d45115f to your computer and use it in GitHub Desktop.
Extract values from JSON, so it can be used to get the wordcount.
const getWordsOfJSONObj = obj => {
let valueText = ''
for (key in obj) {
if (typeof obj[key] === 'object') {
valueText += getWordsOfJSONObj(obj[key])
} else {
valueText += obj[key] + '\n'
}
}
return valueText
}
const getWordsOfJSON = jsonText => getWordsOfJSONObj(JSON.parse(jsonText))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment