bhollis/jsonview

Expose JSON value to global variable

Closed this issue · 6 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]

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

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.

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

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

Sure!

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

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