open-source-parsers / open-source-parsers/jsoncpp

Converting string values to other types

Open
#1,396 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

Is your feature request related to a problem? Please describe.
If you use asString() on ANY type it will convert that value to a string (even if it is not of type string). However, if we try to use asInt, asBool, etc on a string type it results in an exception being thrown. Looking at the code, it doesn't even attempt to convert string types into the desired type (string type is not in the switch statements for integer values).

Describe the solution you'd like
Ideally, the other as functions attempt to convert the string value to the expected value.

Describe alternatives you've considered
We can do this ourselves, by type checking before hand... but this becomes tedious for something that appears to be expected functionality (as it exists with asString).

Additional context
I found this out because I was storing some types as strings even though they were other types (int, bool, etc). Now, going back and trying to implement type specific values I am running into the issue of using asInt when it's stored as a string.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the asInt, asBool, and related conversion entry points, then inspect the switch statements that currently exclude string values. Define the supported string conversions and add coverage for them; done means valid string representations convert to the requested types without exceptions, while invalid values still follow the existing error behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.