Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:48+00:00 2026-06-13T11:19:48+00:00

I’m writing a JSON parser in C++ and am facing a problem when parsing

  • 0

I’m writing a JSON parser in C++ and am facing a problem when parsing JSON strings:

The JSON specification states that JSON strings can contain unicode characters in the form of:

"here comes a unicode character: \u05d9 !"

My JSON parser tries to map JSON strings to std::string so usually, one character of the JSON strings becomes one character of the std::string. However for those unicode characters, I really don’t know what to do:

Should I just put the raw bytes values in my std::string like so:

std::string mystr;
mystr.push_back('\0x05');
mystr.push_back('\0xd9');

Or should I interpret the two characters with a library like iconv and store the UTF-8 encoded result in my string instead ?

Should I use a std::wstring to store all the characters ? What then on *NIX OSes where wchar_t are 4-bytes long ?

I sense something is wrong in my solutions but I fail to understand what. What should I do in that situation ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:19:49+00:00Added an answer on June 13, 2026 at 11:19 am

    After some digging and thanks to H2CO3’s comments and Philipp’s comments, I finally could understand how this is supposed to work:

    Reading the RFC4627, Section 3. Encoding:

    1. Encoding

      JSON text SHALL be encoded in Unicode. The default encoding is
      UTF-8.

      Since the first two characters of a JSON text will always be ASCII
      characters [RFC0020], it is possible to determine whether an octet
      stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
      at the pattern of nulls in the first four octets.

         00 00 00 xx  UTF-32BE
         00 xx 00 xx  UTF-16BE
         xx 00 00 00  UTF-32LE
         xx 00 xx 00  UTF-16LE
         xx xx xx xx  UTF-8
      

    So it appears a JSON octet stream can be encoded in UTF-8, UTF-16, or UTF-32 (in both their BE or LE variants, for the last two).

    Once that is clear, Section 2.5. Strings explains how to handle those \uXXXX values in JSON strings:

    Any character may be escaped. If the character is in the Basic
    Multilingual Plane (U+0000 through U+FFFF), then it may be
    represented as a six-character sequence: a reverse solidus, followed
    by the lowercase letter u, followed by four hexadecimal digits that
    encode the character’s code point. The hexadecimal letters A though
    F can be upper or lowercase. So, for example, a string containing
    only a single reverse solidus character may be represented as
    “\u005C”.

    With more complete explanations for characters not in the Basic Multilingual Plane.

    To escape an extended character that is not in the Basic Multilingual
    Plane, the character is represented as a twelve-character sequence,
    encoding the UTF-16 surrogate pair. So, for example, a string
    containing only the G clef character (U+1D11E) may be represented as
    “\uD834\uDD1E”.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.