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

Read long long int data as a number. #1354

Closed
pauljurczak opened this issue Nov 14, 2018 · 2 comments
Closed

Read long long int data as a number. #1354

pauljurczak opened this issue Nov 14, 2018 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@pauljurczak
Copy link
Contributor

64-bit integers (long long int) are available on most platforms and frequently used in machine learning data sets as sample IDs, but they are currently read as a string and require parsing.

@nlohmann
Copy link
Owner

The library uses std::int64_t and std::uint64_t internally to store integers. There should not be any issue with long long int- in particular, the library will not store numbers as strings. Maybe I misunderstood you.

Here is some example code:

#include "json.hpp"
#include <iostream>

using json = nlohmann::json;

int main()
{
    long long int foo = 123123123123;

    // store a number without parsing
    json j = foo;
    
    // output JSON value
    std::cout << j << std::endl;
    
    // roundtrip
    long long int j_foo = j;
    assert(j_foo == foo);
    
    // parsing creates the same value
    assert(json::parse("123123123123") == j);
}

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Nov 14, 2018
@pauljurczak
Copy link
Contributor Author

You are right. I just noticed that this datum was in fact a string not a long long int. Sorry for a false alarm.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed state: needs more info the author of the issue needs to provide more details labels Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants