javascript-stringify icon indicating copy to clipboard operation
javascript-stringify copied to clipboard

javascript-parse (create object from string generated with javascript-stringify)

Open drschwabe opened this issue 3 years ago • 0 comments

Just wanted to A) see if there is an existing way to do this without being too hacky (see hacky solution below) and if not, B) suggest the feature or a supplementary module to do parsing of javascript-stringified output so that we can create an object from a string generated with javascript-stringify.

Regarding potential existing way, I tried this lib but does not seem to be able to parse an object output with javascript-stringify

https://github.com/greenpioneersolutions/auto-parse

(note for my test I wrote the javascript-stringify output to a file and then performed a fs.readFile(objString, 'utf8') on it and then attempted to read the resulting string with auto-parse)

The way that I found which actually works is a bit hacky and requires Node:

you can write the javascript-stringify output to a string, append module.exports=, write to disk, and perform a require on the resulting file.

related: https://github.com/blakeembrey/javascript-stringify/issues/32

drschwabe avatar Jul 19 '22 16:07 drschwabe