Json: Where is json::parse now?

Created on 9 Aug 2019  路  22Comments  路  Source: nlohmann/json

  • Describe what you want to achieve.
    Trying to parse a string into json and then extract values and create object
    image

class "nlohmann::basic_json" has no member "parse"

Getting error class "nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer>" has no member "parse"

  • Describe what you tried.
#include <iomanip>
#include <fstream>
#include <sstream>

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;
using namespace std;
.
.
.
int main(){
    auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
}
  • Describe which system (OS, compiler) you are using.
    Windows 10
  • Describe which version of the library you are using (release version, develop branch).

VCPKG

nlohmann-json:x64-windows                          3.7.0            JSON for Modern C++
nlohmann-json:x64-windows-static                   3.7.0            JSON for Modern C++
nlohmann-json:x86-windows                          3.7.0            JSON for Modern C++
nlohmann-json:x86-windows-static                   3.7.0            JSON for Modern C++
question visual studio invalid

Most helpful comment

Turns out the error will be fixed in VS 2019 16.4.

Right now it's only available as preview version. You can download and install it from here. Although I wouldn't use it for serious development.

If you need proof:
image
On the left is 16.3 and on the right is 16.4.

So to problem is really caused by VS and not the library itself.

The problem was previously reported on the developper comunity

All 22 comments

In order to asses your issue, we need the following information:

  • What is the issue you have?

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

  • What is the expected behavior?

  • And what is the actual behavior instead?

  • Which compiler and operating system are you using? Is it a supported compiler?

  • If you experience a compilation error: can you compile and run the unit tests?

  • Getting error parse method not found
  • Installed from vcpkg : .\vcpkg.exe insatll nlohmann-json:x64-windows nlohmann-json:x64-windows-static nlohmann-json:x86-windows nlohmann-json:x86-windows-static version3.7
  • Expected behavior : should not get error parse method not found
  • Compiler Visual studio 16.2 : 14.2 (seems supported)
  • will run tests and get back to you
  • What is the exact error message?
  • Can you use the JSON library apart from the parse function? For instance, can you compile a program that does nothing but json j;?
  • Exact error

nlohmann::basic_json" has no member "parse

  • Yes, the below code is compiling and running fine.
#include <iostream>

#include "nlohmann/json.hpp"
using json = nlohmann::json;
using namespace std;
int main()
{
    json j;
    return 0;
}

Strange...

Can you please try:

std::string s = "{ \"happy\": true, \"pi\": 3.141 }";
json j = json::parse(s);

?

I have the same exact behaviour in Visual Studio 2019, using the single include file.
The strangest thing is that everything seems to work correctly when I compile and run the program. Intellisense just refuses to find json::parse() while editing the code and doesn't accept it even after building finished succesfully, as I said before.

Oh, @pmahend1 - does the code compile or is it just an IntelliSense error?

Strange...

Can you please try:

std::string s = "{ \"happy\": true, \"pi\": 3.141 }";
json j = json::parse(s);

?

This fails :Compilation error

Running tests --> I am getting Test not available without configuration. (Missing "-C <config>"?) error i.ePS C:\workspace\json\build> ctest --output-on-failure`

What is the exact compilation error message?

Please ignore. This is intellisense issue. Seems something went wrong with latest visual studio 16.2.1
If I filter out Intellisense errors , this compiles and runs as well.

Thanks!

Please ignore. This is intellisense issue. Seems something went wrong with latest visual studio 16.2.1
If I filter out Intellisense errors , this compiles and runs as well.

So the only solution is to wait for a new build of VS and keep editor errors while developing?

I would not know any other way.

@ERap320 - You might also want to report to Visual Studio at https://developercommunity.visualstudio.com/spaces/62/index.html.

I have reported on developer community

Yup, still getting this error on visual studio 2019 16.2.3.

@nlohmann Not really.
I updated to the newest 3.7.3, still got this error. Though it doesn't affect the compilation, but it is still there FYI.

Turns out the error will be fixed in VS 2019 16.4.

Right now it's only available as preview version. You can download and install it from here. Although I wouldn't use it for serious development.

If you need proof:
image
On the left is 16.3 and on the right is 16.4.

So to problem is really caused by VS and not the library itself.

The problem was previously reported on the developper comunity

@Stefmachine Thanks a lot for checking!

currently using 16.6.3 version of visual studio, and i get the same issue.
i can paste wat for error i get etc. but it is exact the same

gr

Was this page helpful?
0 / 5 - 0 ratings