Is there a way to get just the string value inside `json` when doing stringify?
nooblyf opened this issue · 2 comments
nooblyf commented
when i stringify anything i get json
and meta
(or sometimes just json
) like this
stringify({
flasjhdfojha: 45234524,
fadsfasd: { fasfd: { dfasdfasdf: { fasdfasd: 341234123, date: new Date() } } },
})
// {"json":{"flasjhdfojha":45234524,"fadsfasd":{"fasfd":{"dfasdfasdf":{"fasdfasd":341234123,"date":"2023-08-05T19:39:45.674Z"}}}},"meta":{"values":{"fadsfasd.fasfd.dfasdfasdf.date":["Date"]}}}
stringify("helooooo")
// {"json":"helooooo"}
is there a way to get just the value inside json
as a string? something like
// string
// {"flasjhdfojha":45234524,"fadsfasd":{"fasfd":{"dfasdfasdf":{"fasdfasd":341234123,"date":"2023-08-05T19:39:45.674Z"}}}}
// string
// helooooo
what i'm currently doing is using regex to remove json
(key) and meta
completely (if it exists)
stringify(data).replace(/^(({\"json\":?)(\"?))|(,"meta":.*)|((\"?)(}?$))/gi, '');
Skn0tt commented
nooblyf commented
I wanted this for logging purposes only, i guess JSON.stringify
is the way to go