-4

How to convert "[{"id":6,"name":"r6","preparation_time":"123","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:27:02","updated_at":"2020-09-11 09:27:02"},{"id":5,"name":"r5","preparation_time":"21","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:26:28","updated_at":"2020-09-11 09:26:28"}]"

to [{"id":6,"name":"r6","preparation_time":"123","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:27:02","updated_at":"2020-09-11 09:27:02"},{"id":5,"name":"r5","preparation_time":"21","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:26:28","updated_at":"2020-09-11 09:26:28"}]

2 Answers2

0

Use JSON.parse()

console.log(JSON.parse('[{"id":6,"name":"r6","preparation_time":"123","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:27:02","updated_at":"2020-09-11 09:27:02"},{"id":5,"name":"r5","preparation_time":"21","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:26:28","updated_at":"2020-09-11 09:26:28"}]'))
Always Helping
  • 14,316
  • 4
  • 13
  • 29
gkulshrestha
  • 855
  • 1
  • 6
  • 11
0

The given string is in json format. By using JSON.parse().

$arr = JSON.parse('[{"id":6,"name":"r6","preparation_time":"123","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:27:02","updated_at":"2020-09-11 09:27:02"},{"id":5,"name":"r5","preparation_time":"21","servings":4,"background_media_file":"recipe_background_image","font_color":"#000000","created_at":"2020-09-11 09:26:28","updated_at":"2020-09-11 09:26:28"}]');
console.log($arr);
Umair Khan
  • 1,684
  • 18
  • 34