Home > Net >  JSON.parse error (Unexpected token) with escaped string
JSON.parse error (Unexpected token) with escaped string

Time:07-17

As you can see, the special characters are escaped in the string. But it gives error. The error is related to description part

...Adam Goldberg delivers \"an uproarious study...
                           ^

let str = `{"kinopoisk_url":"https:\/\/www.themoviedb.org\/movie\/1845","tmdb_id":"1845","name":"2 Days in Paris","o_name":"2 Days in Paris","cover_big":"https:\/\/cportal.unibox.us:2087\/images\/4yf8vcgJtADTTPP0Ltq2KhqLfdE_big.jpg","movie_image":"https:\/\/cportal.unibox.us:2087\/images\/4yf8vcgJtADTTPP0Ltq2KhqLfdE_big.jpg","releasedate":"2007-02-09","episode_run_time":0,"youtube_trailer":"","director":"Julie Delpy","actors":"Julie Delpy, Adam Goldberg, Daniel Br\u00fchl, Adan Jodorowsky, Alexandre Nahon, Albert Delpy, Alexia Landeau, Vanessa Seward","cast":"Julie Delpy, Adam Goldberg, Daniel Br\u00fchl, Adan Jodorowsky, Alexandre Nahon, Albert Delpy, Alexia Landeau, Vanessa Seward","description":"Adam Goldberg delivers \"an uproarious study in transatlantic culture panic\" as Jack, an anxious, hypochondriac-prone New Yorker vacationing throughout Europe with his breezy, free-spirited Parisian girlfriend, Marion. But when they make a two-day stop in Marion's hometown, the couple's romantic trip takes a turn as Jack is exposed to Marion's sexually perverse and emotionally unstable family.","plot":"Adam Goldberg delivers \"an uproarious study in transatlantic culture panic\" as Jack, an anxious, hypochondriac-prone New Yorker vacationing throughout Europe with his breezy, free-spirited Parisian girlfriend, Marion. But when they make a two-day stop in Marion's hometown, the couple's romantic trip takes a turn as Jack is exposed to Marion's sexually perverse and emotionally unstable family.","age":"12 ","mpaa_rating":"","rating_count_kinopoisk":253,"country":"France, Germany","genre":"Comedy \/ Romance","backdrop_path":["https:\/\/cportal.unibox.us:2087\/images\/1845_movie_backdrop_0.jpg","https:\/\/cportal.unibox.us:2087\/images\/1845_movie_backdrop_1.jpg"],"duration_secs":6012,"duration":"01:40:12","video":{"index":1,"codec_name":"h264","codec_long_name":"H.264 \/ AVC \/ MPEG-4 AVC \/ MPEG-4 part 10","profile":"High","codec_type":"video","codec_time_base":"1001\/48000","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":1280,"height":698,"coded_width":1280,"coded_height":704,"has_b_frames":2,"sample_aspect_ratio":"1:1","display_aspect_ratio":"640:349","pix_fmt":"yuv420p","level":31,"chroma_location":"left","field_order":"progressive","refs":1,"is_avc":"true","nal_length_size":"4","r_frame_rate":"24000\/1001","avg_frame_rate":"24000\/1001","time_base":"1\/1000","start_pts":0,"start_time":"0.000000","bits_per_raw_sample":"8","disposition":{"default":1,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0},"tags":{"title":"Ganool.com","DURATION":"01:40:12.672000000"}},"audio":{"index":0,"codec_name":"aac","codec_long_name":"AAC (Advanced Audio Coding)","profile":"HE-AAC","codec_type":"audio","codec_time_base":"1\/48000","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","sample_fmt":"fltp","sample_rate":"48000","channels":2,"channel_layout":"stereo","bits_per_sample":0,"r_frame_rate":"0\/0","avg_frame_rate":"0\/0","time_base":"1\/1000","start_pts":31,"start_time":"0.031000","disposition":{"default":1,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0},"tags":{"language":"eng","title":"Ganool.com","DURATION":"01:40:12.745000000"}},"bitrate":1048,"rating":"6.3","backdrop":"https:\/\/cportal.unibox.us:2087\/images\/1845_movie_backdrop_0.jpg\r\nhttps:\/\/cportal.unibox.us:2087\/images\/1845_movie_backdrop_1.jpg\r\n","rating_mpaa":"R"}`;

console.log(JSON.parse(str));

CodePudding user response:

Doing let str = `...` turns \" to just ". That's why you're getting an error.

Try let str = String.raw`...`. Works for me

  • Related