Search code examples
ruby-on-railsjsonrubyarabic

Parsing json on ruby, arabic unicode


I get json parse error on ruby code the article is on arabic because of :

JSON.parse(open('https://www.examlpe.com/wp-json/wp/v2/posts').read)
<p dir=\"rtl\">\u0623\u0639\u0644\u0646\u062a \u0627\u0644\u0634\u0631\u0643\u0629 \u0627\u0644\u0648\u0637\u0646\u064a\u0629 \u0644\u0644\u0646\u0642\u0644 \u0628\u0627\u0644\u0633\u0643\u0643 .<\/p>

Solution

  • I get the solution by remove the BOM

    JSON.parse(open('https://www.example.com/wp-json/wp/v2/posts').read.gsub!("\xEF\xBB\xBF".force_encoding("UTF-8"), '')