in reply to Re: JSON character encoding
in thread JSON character encoding

Hi thanks for the reply. Here is the JSON response. The strange apostrophe is still there (but only from some Youtube channels, others are normal). It's literally what I get after just these two steps:
my $url = "https://www.googleapis.com/youtube/v3/..."; my $result = get($url);
JSON received: { "items": [ { "snippet": { "description": "#BellatorNYC is headed to Madison Square Garden for an epic night of fights! \n\nSubscribe for more Bellator MMA content! http://bit.ly/SubscribeBellatorYT \n\nFollow Bellator MMA\nFacebook: https://www.facebook.com/BellatorMMA\nTwitter: https://twitter.com/BellatorMMA\nInstagram: https://instagram.com/bellatormma/\nSnapchat: BellatorNation\n\nJoin #BellatorNation to gain exclusive access and benefits including fan-fests, ticket presales and much more! http://bellator.com/newsletter\n\nCheck out the Bellator MMA App: http://bellator.spike.com/app\niTunes: http://bit.ly/1tHUGym \nAndroid: http://bit.ly/1OaBqDX\n\nAbout Bellator MMA: \nBellator MMA is about the fighters and the fans. It’s the fighters who put it all on the line each day, leaving every ounce of themselves inside the cage. Our mission is to create, promote and produce the most exciting, competitive and entertaining Mixed Martial Arts competition in the world.\n\nBellator is available to nearly 500 million homes worldwide in over 140 countries. In the United States, Bellator can be seen on Spike, the MMA television leader. Based in Hollywood, California, Bellator is owned by entertainment giant Viacom, home to the world's premier entertainment brands that connect with audiences through compelling content across television, motion picture, online and mobile platforms. Website: http://bellator.spike.com/" } } ] }

You're right, the emoticon was some perl language I inserted somehow. The actual JSON for the emoticon is here:
 { "items": [ { "snippet": { "description": "Happy with everything at the moment 😊" } } ] }

Replies are listed 'Best First'.
Re^3: JSON character encoding
by Anonymous Monk on May 29, 2017 at 20:03 UTC
    Yes, both of those are just UTF-8. The trick is to put them in a form that your output device can handle. If you're in a terminal window, it might not to be able to display weird unicode characters like smileys. You might try something like this:
    use Encode qw( encode FB_HTMLCREF ); print encode('ascii', $jsonstuff->{items}[0]{snippet}{description}, FB +_HTMLCREF), "\n";
    You'll get "It’s" and "moment 😊", which are ugly, but should come out right if you put them in an html file.
      IT WORKED! Now all the little smileys, arrows, etc. show up in my final HTML output. Much thanks for the tip. I just put my final html content file through your encode process before outputting to web:
      $pagecontent = encode('ascii', $pagecontent, FB_HTMLCREF);

      p.s. for anyone reading this later: If you store your JSON data in a file, then you need to access it explicitly as utf8:
      open(my $fh, '<:utf8', $filename)
      I had to do this and use Anonymous Monk's FB_HTMLCREF process to finally get the emoticons to show.