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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:57:55+00:00 2026-05-15T21:57:55+00:00

We have a .properties file that has some values persisted as JSON. I keep

  • 0

We have a “.properties” file that has some values persisted as JSON. I keep getting bitten by special characters, though — the org.json.JSONObject isn’t very verbose about what causes it to choke, so it takes forever to figure out that I wrote {"key":"this is a \"Value\""}, but I read {"key":"this is a "Value""}. Obviously, the latter is going to give the JSON parser fits. Rather than poking at it by trial-and-error, can anybody just tell me the right way to escape the value (which in this case is of course the entire JSON string…) before passing it to the PropertiesConfiguration class to be written to a file?

  • 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-15T21:57:56+00:00Added an answer on May 15, 2026 at 9:57 pm

    I think I may have found the disconnect. I thought we had something along the lines of

    PropertiesConfiguration pc = new PropertiesConfiguration();
    pc.addProperty("SomeKey",
      new JSONObject().put("Stuff", getUserInput()).toString());
    pc.save(myWriter);
    

    Now, imagine that the user supplies the string This is "Interesting".... My problem comes because while the string will be stored with the quotes properly escaped, the properties file will wind up with

    SomeKey={\"SomeKey\":\"This is \"Interesting\"\"}
    

    which is of course horribly broken. Here’s why it was happening (I think). Instead of using the PropertiesConfiguration class to create the properties file as in the ideal code above, the original code was more like

    myWriter.write(keyName + "=" +
      new JSONObject().put("Stuff", getUserInput()).toString());
    

    which of course only escapes the user input for the JSON, but does not further escape the JSON for the Properties parser. I can’t swear to it without additional testing, but it looks like the pc.AddProperty() method will escape its arguments (again) if need be.

    End result: it’s my fault that I assumed the guy who wrote the code I’m working on was using the APIs provided to him, rather than “going rogue” and trying to create the required format directly.

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

Sidebar

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.