Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to extract numbers in the string? #1865

Closed
grancia opened this issue Dec 9, 2019 · 4 comments
Closed

Best way to extract numbers in the string? #1865

grancia opened this issue Dec 9, 2019 · 4 comments

Comments

@grancia
Copy link

grancia commented Dec 9, 2019

Given following string having double quotes in input string, what is the best way to extract numbers only with nlohmann json?
input: "{'data_a': [1, 2], 'data_b': [3, 4]}"

@nickaein
Copy link
Contributor

nickaein commented Dec 9, 2019

Have you read the examples? This will be pretty straightforward if the input is valid JSON string.

@grancia
Copy link
Author

grancia commented Dec 9, 2019

I have checked but it looks a bit different case.
For example, if json file looks like below how can we extract number from them? Meaning in case, the data's value is double quoted...
{"data": "{'data_a': [1, 2], 'data_b': [3, 4]}"}

@nickaein
Copy link
Contributor

nickaein commented Dec 9, 2019

In this case your input is valid JSON string, but data field is a string containing {'data_a': [1, 2], 'data_b': [3, 4]}. The contents are not an valid JSON string as keys are single quoted. One approach to extract the number might be:

https://wandbox.org/permlink/DQ9FSnoaEELbwJhG

@grancia
Copy link
Author

grancia commented Dec 9, 2019

fixed! thank you!

@grancia grancia closed this as completed Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants