How can i convert json array in string format into array[]

user12741566

I am rendering this data in a table, how can I convert Cuisine_style into array???

[
  {
    "Name": "Martine of Martine's Table",
    "City": "Amsterdam",
    "Cuisine_Style": "['French', 'Dutch', 'European']",
    "Ranking": 1,
    "Rating": 5,
    "Number of Reviews": 136
  },
  {
    "Name": "De Silveren Spiegel",
    "City": "Amsterdam",
    "Cuisine_Style": "['Dutch', 'European', 'Vegetarian Friendly', 'Gluten Free Options']",
    "Ranking": 2,
    "Rating": 4.5,
    "Number of Reviews": 812
  }
]
C. Lewis

This is not an endorsement of bad object serialization

If you absolutely must consume the data in this format, you can replace the single quotes with double quotes to make them JSON-compliant:

const data = [
  {
    "Name": "Martine of Martine's Table",
    "City": "Amsterdam",
    "Cuisine_Style": "['French', 'Dutch', 'European']",
    "Ranking": 1,
    "Rating": 5,
    "Number of Reviews": 136
  },
  {
    "Name": "De Silveren Spiegel",
    "City": "Amsterdam",
    "Cuisine_Style": "['Dutch', 'European', 'Vegetarian Friendly', 'Gluten Free Options']",
    "Ranking": 2,
    "Rating": 4.5,
    "Number of Reviews": 812
  }
];

for (const item of data)
    item['Cuisine_Style'] = JSON.parse(item['Cuisine_Style'].replace(/'/g, '"'));

console.log(data);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert an Array to Json (Java)

How can I convert a String to a char array?

How can I convert a string to JSON and save the data in an array?

How can I convert an Int array into a String? array in Swift

How can I convert the object array to GraphQL format in Javascript?

Scala Spark How can I convert a column array[string] to a string with JSON array in it?

How can I convert from .csv to array/json/string in node.js

how to convert string to array ? as i am getting an array but it is in string format

How can I convert an array to string in swift?

How to convert json into String array

How can I convert to Json Object to Json Array in Karate?

How can I format an array?

How can I convert a json string to a json array using Newtonsoft?

How convert "string with array format" to array in php?

How can I convert string to a array?

How do I convert an Array with a JSON string into a JSON object (ruby)

How can I use Lambda to convert a String array to Integer array?

How can i convert an array

How can I convert JSON Array to array in PHP?

How can I convert string to array in JavaScript?

How can I convert/format a json string with bash

How can I convert an array to JSON?

Javascript convert Json to an array string format

How can I sort an Array of String format of Int Type in Swift

How can i convert an array in Json string to c# object?

How can I convert a string containing data in a specific format into an array of associative arrays in PHP?

How to convert a NumPy array to a string with the same format it can be set with?

How can I convert an array of string arrays into an array of objects?

What format is this, and how do I convert a byte array into this string format?