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 846523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:37:39+00:00 2026-05-15T06:37:39+00:00

When creating JSON data manually, how should I escape string fields? Should I use

  • 0

When creating JSON data manually, how should I escape string fields? Should I use something like Apache Commons Lang’s StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml, or should I use java.net.URLEncoder?

The problem is that when I use SEU.escapeHtml, it doesn’t escape quotes and when I wrap the whole string in a pair of 's, a malformed JSON will be generated.

  • 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-05-15T06:37:40+00:00Added an answer on May 15, 2026 at 6:37 am

    Ideally, find a JSON library in your language that you can feed some appropriate data structure to, and let it worry about how to escape things. It’ll keep you much saner. If for whatever reason you don’t have a library in your language, you don’t want to use one (I wouldn’t suggest this¹), or you’re writing a JSON library, read on.

    Escape it according to the RFC. JSON is pretty liberal: The only characters you must escape are \, ", and control codes (anything less than U+0020).

    This structure of escaping is specific to JSON. You’ll need a JSON specific function. All of the escapes can be written as \uXXXX where XXXX is the UTF-16 code unit¹ for that character. There are a few shortcuts, such as \\, which work as well. (And they result in a smaller and clearer output.)

    For full details, see the RFC.

    ¹JSON’s escaping is built on JS, so it uses \uXXXX, where XXXX is a UTF-16 code unit. For code points outside the BMP, this means encoding surrogate pairs, which can get a bit hairy. (Or, you can just output the character directly, since JSON’s encoded for is Unicode text, and allows these particular characters.)

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

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should really consider using the new JSF 2.0 view… May 16, 2026 at 2:41 pm
  • Editorial Team
    Editorial Team added an answer Use GetEnvironmentVariable to look for the PROCESSOR_ARCHITEW6432 variable. If it… May 16, 2026 at 2:41 pm
  • Editorial Team
    Editorial Team added an answer Your query is returning an IQueryable<MailListViewModel>, essentially one MailListViewModel for… May 16, 2026 at 2:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm creating a simple API that creates typed classes based on JSON data that
I am using jsTree for creating a documentation list index. I use JSON to
I just ran into something weird. I have two JSON arrays which holds different
I have the code below. The line string content = twitterMsg.text; is creating the
I am creating a JSON object dynamically and when I send it via an
I am dynamically creating forms from a JSON object that I fetch with a
I am creating a mobile application using j2me, which interacts with a webservice. The
Iam having problem creating postgresql function in plperl CREATE OR REPLACE FUNCTION zm_json (TEXT,
I am trying to get a JSON response from our server and the response
First a bit of background: We have a growing RESTful service layer supporting web

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.