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

  • Home
  • SEARCH
  • 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 6005947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:28:13+00:00 2026-05-23T01:28:13+00:00

I would like to validate the JSON being passed in, currently the method is

  • 0

I would like to validate the JSON being passed in, currently the method is not parsing the JSON and bad json will go on to break everything, and I imagine security exploits can be built into a bad JSON string as well.

JsonParser parser = new JsonParser();
JsonObject bodyvar = parser.parse(params.get("body")).getAsJsonObject();

How can I check validate the JSON? (ideally I can get a boolean value or a 1 or 0 returned, so I can construct this method conditionally. Or if there is a try/catch that comes with the JSONParser for validation, that would be cool too)

edit: using GSON library (and I’ll be looking at the GSON reference while I wait for answers here)

  • 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-23T01:28:13+00:00Added an answer on May 23, 2026 at 1:28 am

    Without knowing which library you’re using, it’s hard to be specific, but most parsing libraries will throw an exception if the JSON was mal-formed, so you shouldn’t have to worry about the JSON going on to break anything else. If you simply throw a try/catch block around the call to parser.parse(), you’ll probably be in pretty good shape.

    And JSON can’t really hurt anything server-side, so unless you’re planning to pass this JSON string from one user’s browser to another, you won’t have any security vulnerabilities from it anyway.

    Edit

    Since you’re using gson, a JsonSyntaxException will be thrown if the JSON is mal-formed. You can catch that exception specifically if there’s something you want to do differently in that case.

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

Sidebar

Related Questions

Would like to make anapplication in Java that will not automatically parse parameters used
I would like to validate the textbox for specific text and it must not
I have a schema that I would like to validate (note: not a document,
I would like to validate an email using the RegexValidator, e.g. [RegexValidator(@^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$)] Which works
I'm using jQuery Validate and would like to re-validate a group of fields whenever
I have some MET data I want to validate which would look something like
I would like to validate some objects. The validation has two parts: validation whether
I would like to validate the presence of a file with paperclip. When I
I have a simple form that I would like to validate on form submission.
I'm a noob to JSON, and would like to do a foreach through all

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.