how can we flatten a json file in nodejs using recursion?

Try this I am just correcting @Konstantin Pribluda

const r = { ...} // Input JSON
JSON.parse(JSON.stringify(r).replace(/{\s*"_text":\s*("[^"]*")\s*}/g, "$1").replace(/"[^"]*"\s*:\s*{},/g,""))

Second, replace for empty {}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top