I am currently working on a function that accepts unformatted JSON code as input and I am attempting to utilize the stringify method to format it into a more visually appealing (pretty) view. Here is the code snippet:
function prettyPrintJSON(selectionInfo) {
const unformattedJSON = selectionInfo.selectionText
const formattedJSON = JSON.stringify(unformattedJSON, null, '\t')
}
Below is the unformatted JSON code:
{"colors":[{"color":"black","category":"hue","type":"primary","code":{"rgba":[255,255,255,1],"hex":"#000"}},{"color":"white","category":"value","code":{"rgba":[0,0,0,1],"hex":"#FFF"}},{"color":"red","category":"hue","type":"primary","code":{"rgba":[255,0,0,1],"hex":"#FF0"}},{"color":"blue","category":"hue","type":"primary","code":{"rgba":[0,0,255,1],"hex":"#00F"}},{"color":"yellow","category":"hue","type":"primary","code":{"rgba":[255,255,0,1],"hex":"#FF0"}},{"color":"green","category":"hue","type":"secondary","code":{"rgba":[0,255,0,1],"hex":"#0F0"}}]}
Here is how it is displayed in the table: https://i.sstatic.net/csWkv.png
However, the JSON code appears unformatted. Additionally, I am developing a Google Chrome extension and using Vue.js framework to create a table for displaying various data types. Any suggestions on what might be missing? Thank you.