Take the 2-minute tour ×

I have just installed libjson from sourceforge.net . I tried executing a simple program But i get this error

‘JSONNode’ was not declared in this scope

Here is the code


#include <libjson.h>

int main()
    JSONNode n(JSON_NODE);
    c.push_back(JSONNode("", 16));
    c.push_back(JSONNode("", 43));
    c.push_back(JSONNode("", 69));


    std::string jc = n.write_formatted();

    return 0;

M I missing some header file ?

share|improve this question
Did you make sure libjson.h was saved in the same project folder as this .cpp file? –  0x499602D2 Aug 20 '12 at 11:58
Is it in some namespace? –  Lyubomir Vasilev Aug 20 '12 at 12:01
add comment

4 Answers

up vote 1 down vote accepted

I see that libjson stuff is defined in the json namespace. Please try adding json:: in front of JSONNode solve the problem? Like this:

json::JSONNode n(JSON_NODE);
json::JSONNode c(JSON_ARRAY);
share|improve this answer
didnt solve the problem . I get 'json has not been declared' error. –  Vihaan Verma Aug 20 '12 at 12:11
On which line is the error? Did you place json:: in front of the other too? –  Lyubomir Vasilev Aug 20 '12 at 12:28
I tired replacing as you pointed out . It complains that 'json' has not been declared. –  Vihaan Verma Aug 20 '12 at 12:51
add comment

You need to disable #define JSON_LIBRARY in JSONOptions.h, otherwise libjson won't include the C++ headers.

share|improve this answer
add comment

You have to make sure to build the libJson library first.

I followed the following thread and it worked great for me after having the same problem you are having:

For running the Make File: http://stackoverflow.com/a/11865407/1399434e

share|improve this answer
add comment

disable the JSON_LIBRARY in JSONOptions.h

//#define JSON_LIBRARY

then compile again as below

#include "libjson.h"
using namespace libjson;

int main(int argc, char* argv[])

    JSONNode* pNode = NULL;
    return 0;
share|improve this answer
add comment

Your Answer


