Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

How to convert json blob to json

Open wktdev opened this issue 4 years ago • 6 comments

I want to convert this:

const blob = await exportDB(db, { prettyJson: true });

To readable json.

Instead I get:

Blob {size: 5646, type: "text/json"}

Thank you.

wktdev avatar Mar 15 '20 07:03 wktdev

I found an answer. It uses the file reader.

Is there a "Dexie.js specific" way that I can do this ?

Here is what works:


  const fr = new FileReader();

		fr.addEventListener("load", e => {
		  console.log(e.target.result, JSON.parse(fr.result))
		});

		fr.readAsText(blob);

wktdev avatar Mar 15 '20 07:03 wktdev

Theres sugar for that. Would probably be useful.

dfahlander avatar Mar 26 '20 00:03 dfahlander

To convert blob to json use

let jsonString =  await blob.text() 
let json = JSON.parse(jsonString)

MishaAkram avatar Feb 21 '24 06:02 MishaAkram

Does this require a pull requests to implement? (I am new to this repo)

If so, @MishaAkram , did you want to create the pull request?

If so and @MishaAkram is not planning on creating a pull request, I am happy to do that. I am looking for a first issue to contribute to.

JamieBort avatar Mar 26 '24 17:03 JamieBort

@JamieBort I don't intend to create a PR out of it, just shared a general solution

MishaAkram avatar Mar 26 '24 17:03 MishaAkram

Thanks for the quick response, @MishaAkram. Does anyone know who to contact about this? For example, is there a team of maintainers?

JamieBort avatar Mar 26 '24 22:03 JamieBort