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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:30:38+00:00 2026-06-04T01:30:38+00:00

I have some objects that I’m parsing from json using native browser implementations. Some

  • 0

I have some objects that I’m parsing from json using native browser implementations. Some of the objects’ properties are numbers. For the moment, the numbers are parse from json as strings and I use parseInt to cast the string to the int I need.

The problem is that I’ve got 23 objects I do this with and overall about 80 properties that I’m parsing to ints like this:

if (TheObject && TheObject.TheProperty) {
   TheObject.TheProperty = parseInt(TheObject.TheProperty, 10);
}

There are many lines of code that look very similar. Is there a way using prototypes or something to change the way the JSON.parse function works so that each time the parser runs it checks to see if a string property is actually an int and if so cast it directly as such?

Thanks.

  • 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-04T01:30:40+00:00Added an answer on June 4, 2026 at 1:30 am

    JSON can handle numbers as follow:

    {
        "TheObject":{
            "TheProperty":5
        }
    }
    

    If your property was doublequoted then it’s a string else it’s a numeric, boolean (true and false values), null or just something that cause parse error.

    See http://json.org/

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

Sidebar

Related Questions

I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I have a Python script that for-loops through some objects and fetches data from
Lets say I have some domain objects that will need to be serialized/packed using
I have some .NET 4 entity framework objects that I get from the DB,
I have a project that contains several submodules, that communicate using some objects that
In my project I have some objects that I show from a server, lets
I have a library with some objects that I use both from C# and
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
Assume some domain and view objects (that have no common base class) public class
I have several objects in my app that can become nil at some point

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.