jsonview icon indicating copy to clipboard operation
jsonview copied to clipboard

Expose JSON value to global variable

Open mokkabonna opened this issue 6 years ago • 5 comments

It would be really nice if the parsed JSON string would be exposed as a global variable. This way people can just open devtools and manipulate the data quickly.

Something like this (with data as the variable name, and an array as the value)

var ids = data.map(value => value.id)
console.log(ids) // [1, 2, 3]

mokkabonna avatar Jun 08 '18 08:06 mokkabonna

This is a neat idea, but how would anyone know that this is happening?

bhollis avatar Nov 10 '18 23:11 bhollis

It could let them know in the console ("JSON exposed as data" for example). I know I open the console to start messing with the data so this seems like a good place. Or just mention it in the docs.

My current workflow is to copy everything, paste in the console, and assign to a variable. I can only speak for myself but I would have to imagine I'm not the only one that does this somewhat frequently.

rosshadden avatar Nov 11 '18 16:11 rosshadden

I suppose if someone wanted to make a PR, that's be cool.

bhollis avatar Sep 05 '20 05:09 bhollis

@bhollis I'd like to work on this issue if possible.

osopromadze avatar Oct 23 '21 21:10 osopromadze

Sure!

bhollis avatar Oct 24 '21 03:10 bhollis

For the moment, this appears to work for me in Firefox...

data = JSON.parse(JSONView.json.textContent)

asharpe avatar Mar 07 '23 03:03 asharpe