linuxjsonunixunicodeencoding

How to convert \uXXXX unicode to UTF-8 using console tools in *nix


I use curl to get some URL response, it's JSON response and it contains unicode-escaped national characters like \u0144 (ń) and \u00f3 (ó).

How can I convert them to UTF-8 or any other encoding to save into file?


Solution

  • I don't know which distribution you are using, but uni2ascii should be included.

    $ sudo apt-get install uni2ascii
    

    It only depend on libc6, so it's a lightweight solution (uni2ascii i386 4.18-2 is 55,0 kB on Ubuntu)!

    Then to use it:

    $ echo 'Character 1: \u0144, Character 2: \u00f3' | ascii2uni -a U -q
    Character 1: ń, Character 2: ó