Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
parse rawData twice to make sure that we get the JSON object
Browse files Browse the repository at this point in the history
consider the following string "{\"a\":2,\"b\":4,\"c\":6}". When JSON.parse is called on this string, we get "{"a":2,"b":4,"c":6}", but here is the catch: this is a string. So we have to run JSON.parse twice to get the actual object 🤡

This caused the JSON on the data browser to be shown as a string as opposed to a prettified JSON.

See this SO post for more details https://stackoverflow.com/questions/42494823/json-parse-returns-string-instead-of-object
  • Loading branch information
CahidArda committed May 24, 2024
1 parent 442c2dc commit 037ac9e
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const prettifyData = (data: string) => {

const rawToObject = (rawData: string) => {
try {
return JSON.parse(rawData);
return JSON.parse(JSON.parse(rawData));
} catch (_error) {
return rawData;
}
Expand Down

0 comments on commit 037ac9e

Please sign in to comment.