|
|
Comments and Discussions
|
|
 |

|
Hi Mac Users,
now you can install this nice little library with:
sudo port install json_spirit
Happy coding
:q! Uwe
--
mail@uwe-arzt.de
www.uwe-arzt.de
|
|
|
|

|
Hi John,
first: keep up the good work
second: is there an download location available which doesn't need an login? I have build a Macports package which i can't release at the moment, because it works only when you are logged in before. Or is it OK to provide an additional download from my Website?
Thanks
:q! Uwe
--
mail@uwe-arzt.de
www.uwe-arzt.de
|
|
|
|

|
It would be nice to have setter methods to allow for in-place update of json_spirit::Value, json_spirit::Value.
Thanks.
|
|
|
|

|
When I call the json_spirit::write_formatted( ..) function, how can I make it print new lines that are embedded in the character strings like so "this string\n should appear on\n three separate lines.
modified on Thursday, June 3, 2010 4:47 PM
|
|
|
|

|
Hi,
after some testing on 64bit-Linux, the json_spirit-library seems to work only for JSON array-objects (like [...] or [[...],[...]] and the like as in the demo example file 'test.txt') and not for JSON objects limited by curly brackets (e.g. Firefox bookmark files).
Is this true ?
Best regards
Rainer-E
|
|
|
|

|
I'm trying to install json_spirit_v4.03 to the locations where boost is installed.
I'm running on Fedora 12.
I followed the instructions in README.cmake, exported
BOOST_INCLUDEDIR=/usr/include/boost/
BOOST_ROOT=/usr/lib64
Building works as expected, but "make install" (without root permission on purpose, so that I'll see where it tries to install)
tries to install to the wrong locations:
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/include/json_spirit.h
CMake Error at cmake_install.cmake:36 (FILE):
file INSTALL cannot copy file
"/home/dan/Download/json_spirit_v4.03/json_spirit/json_spirit.h" to
"/usr/local/include/json_spirit.h".
How do I get it to install the library to BOOST_ROOT and the includes to BOOST_INCLUDEDIR?
(Not manually, I'll need to deploy to multiple computers).
Thanks,
Dan
|
|
|
|

|
I have downloaded your project code which contains 5 projects, I have install boost 1.41, I builded the solution and it seems fine. But I found there are not .exe files have been created (But the demo cpp have main function). Also, No json_spirit_lib.lib has been created, why?
I try to add cpp and h files under json_spirit_lib to my VC 2005 project But it doesnt work. You said there were two different ways to use your library. Could you explain more detail? I am really a C++ dummy.
Regards
Oscar
|
|
|
|

|
[ 8%] Building CXX object json_spirit/CMakeFiles/json_spirit.dir/json_spirit_reader.cpp.o
"/opt/SUNWspro/prod/include/CC/Cstd/./istream", line 432: Error: Cannot use std::istream * to initialize std::wistream *.
"/test/logging/json_spirit_v4.03/json_spirit/json_spirit_reader_template.h", line 588: Where: While instantiating "std::istream_iterator<wchar_t, wchar_t, std::char_traits<wchar_t>, int>::istream_iterator()".
"/test/logging/json_spirit_v4.03/json_spirit/json_spirit_reader_template.h", line 588: Where: Instantiated from json_spirit::Multi_pass_iters<std::wistream>::Multi_pass_iters(std::wistream &).
"/test/logging/json_spirit_v4.03/json_spirit/json_spirit_reader_template.h", line 598: Where: Instantiated from json_spirit::read_stream<std::wistream, json_spirit::Value_impl<json_spirit::Config_vector<std::wstring>>>(std::wistream &, json_spirit::Value_impl<json_spirit::Config_vector<std::wstring>>&).
"/test/logging/json_spirit_v4.03/json_spirit/json_spirit_reader.cpp", line 55: Where: Instantiated from non-template code.
1 Error(s) detected.
make[2]: *** [json_spirit/CMakeFiles/json_spirit.dir/json_spirit_reader.cpp.o] Error 1
make[1]: *** [json_spirit/CMakeFiles/json_spirit.dir/all] Error 2
make: *** [all] Error 2
Please help me out in resolving the problem or how to avoid the problem.
|
|
|
|

|
I am new to JSON and the Std template library and would really benefit by a more complex example than the Address struct, though it seems straightforward. For example, reading a JSON string containing several top level objects, each containing arrays of their own objects, each of which could contain strings, ints, and arrays of other objects, and inflating vectors of objects/structs from this.
The Address example is quite useful, but a more real non-trivial example would be ideal for a quick-start on a complex subject involving tight deadlines. It would make your library less of a stuggle when concurrently learning complicated technologies.
Thank you,
Paul
|
|
|
|

|
Can the Value or wValue type object stored in shared memory use boost.interprocess?
|
|
|
|

|
Just wanted a bit of clarification. The documentation says to uncomment the define of BOOST_SPIRIT_THREADSAFE if using in multiple threads. But does this alone make json_spirit Values / Objects thread-safe? Or is it still necessary to protect each object with a mutex, if multiple threads can be reading/writing an object? I'm assuming we still have to mutex-protect the object, but I'm new to Boost, so I wasn't sure if there was some magic going on that I didn't see.
Thanks,
Mike
|
|
|
|

|
Hi,
I have a question about allowed version of boost.
I have tried to configure json_spirit with boost-1_36 and got the following error.
Unable to find the requested Boost libraries.
Boost version: 1.36
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.37 (or newer).
Call Stack (most recent call first):
json_spirit/CMakeLists.txt:6 (FIND_PACKAGE)
I found it is caused by json_spirit/CMakeLists.txt having 'FIND_PACKAGE(Boost 1.37 REQUIRED)'.
I think json_spirit can be used with boost 1.34.0 or later, so the version in CMakeLists.txt is wrong.
Is it correct?
|
|
|
|

|
Hello again,
The library's working great so far; I'm using it to parse some JSON config files for an application.
In order to provide better documentation of my config files, I decided to add perl-style comments:
#Single-line comments, beginning with a hash sign
To do this, I added "comment_" to the "value_" and "rule" declarations in json_spirit_reader.cpp. I then added the comment rule:
comment_ = ch_p('#') >> *lex_escape_ch_p ;
This compiles, and my initial tests with it work, but it means that my application logic must catch and discard all comments, which seems wasteful and error-prone. I've read through the Boost::Spirit documentation, and it seems that I should be able to just "ignore" comments, the same way whitespace is ignored. But my head is still spinning from the Spirit User's Guide, and I've no idea how to make this work.
I realize this is outside the scope of json_spirit (it's not in the json specs), but I was wondering if you had any advice about implementing comments on top of json_spirit. I feel like I'm only two or three lines away from getting this to work properly, and I'd really appreciate any input you might have.
Thanks,
-->Seth
|
|
|
|

|
I have a problem using your library with std::strings
containing utf-8 encoded text; the library escapes the
utf8 data, because it thinks it is non printable data.
Any way to get around this? (Besides using utf-16 in
std::wstrings) Maybe an option to disable the escaping
or setting the encoding?
|
|
|
|

|
Hi,
I'm trying to convert a small json string to map,
but with no success .
This the code I wrote:
char* res = "{\"responseData\": {\"translatedText\":\"hola mundo\"}, \"responseDetails\": null, \"responseStatus\": 200}";
Value_type value;
String_type in_s( to_str( res ) );
read_or_throw( in_s, value );
if (value.type()==obj_type)
{
Object_type obj;
obj = value.get_obj();
map<String_type,Value_type> mp_obj;
for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
mp_obj[ i->name_ ] = i->value_; <big></big>
}
but I get compilation error:
error C2039: 'name_' : is not a member of 'std::pair<_Ty1,_Ty2>'
Do u know what can cause the problem ?
I've added this code in
"json_spirit::test_reader, run_tests()"
10x for any help
|
|
|
|

|
thanks your code!
how to parse the string of {"a":1,"c" ,"dog":{"dogId":3,"isHungry" },"e":5,"exp":48810,"farmlandStatus":[{"a":34,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":26,"l":15,"m":15,"n":{"10177679":1,"16513950":1,"19783570":1,"20194034":1,"2175835":1,"25779663" ,"328410816":1,"3663649":1,"3783771":1,"41503729" ,"41892699" ,"43477953" ,"4469715" ,"532102" ,"538815525":1,"649460555" ,"8374675":1},"o" ,"p":[],"q":1260201288,"r":1260489476},{"a":55,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":28,"l":16,"m":16,"n":{"125462791":1,"13331147":1,"16513950":1,"2175835" ,"25779663":1,"294887051":1,"328410816" ,"3663649" ,"3783771" ,"41403882" ,"41503729" ,"41892699":1,"43477953":1,"4469715" ,"63322968":1,"649460555" ,"75031690":1,"8374675" ,"943310677":1},"o" ,"p":[],"q":1260321306,"r":1260492177},{"a":31,"b":1,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k" ,"l" ,"m" ,"n":[],"o" ,"p":[],"q":1260407625,"r":1260598769},{"a":34,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":30,"l":17,"m":17,"n":{"10177679" ,"16513950":1,"19783570":1,"20194034" ,"2175835":1,"25779663" ,"328410816" ,"3663649":1,"3783771":1,"41503729":1,"41892699":1,"43477953":1,"4469715" ,"532102" ,"538815525":1,"63322968":1,"649460555":1,"8374675":1},"o" ,"p":[],"q":1260201287,"r":1260490120},{"a":55,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":26,"l":15,"m":15,"n":{"16513950":1,"25779663" ,"3663649":1,"41503729":1,"41892699":1,"43477953":1,"4469715":1},"o" ,"p":[],"q":1260321278,"r":1260485140},{"a":31,"b":1,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k" ,"l" ,"m" ,"n":[],"o" ,"p":[],"q":1260407626,"r":1260595185},{"a":34,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":31,"l":18,"m":18,"n":{"10177679" ,"16513950":1,"19783570":1,"20194034":1,"2175835" ,"25779663":1,"328410816":1,"3663649":1,"3783771" ,"41503729":1,"41892699":1,"43477953" ,"4469715" ,"532102" ,"538815525" ,"63322968":1,"649460555":1,"8374675":1},"o" ,"p":[],"q":1260201287,"r":1260490120},{"a":55,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":25,"l":14,"m":14,"n":{"125462791" ,"13331147":1,"16513950":1,"2175835":1,"25779663" ,"328410816" ,"3663649":1,"3783771":1,"41503729":1,"41892699":1,"43477953" ,"4469715":1,"63322968":1,"649460555":1,"8374675" ,"943310677":1},"o" ,"p":[],"q":1260321277,"r":1260491057},{"a":31,"b":1,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k" ,"l" ,"m" ,"n":[],"o" ,"p":[],"q":1260407626,"r":1260595186},{"a":34,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":32,"l":19,"m":19,"n":{"10177679":1,"16513950":1,"19783570":1,"20194034":1,"25779663":1,"3663649":1,"3783771":1,"41503729":1,"41892699":1,"532102" ,"538815525":1,"649460555":1,"8374675":1},"o" ,"p":[],"q":1260201286,"r":1260483680},{"a":55,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":25,"l":14,"m":14,"n":{"16513950":1,"2175835":1,"25779663":1,"328410816":1,"3663649":1,"3783771" ,"41503729":1,"41892699":1,"43477953":1,"4469715":1,"63322968":1,"649460555" ,"8374675":1},"o" ,"p":[],"q":1260321276,"r":1260490120},{"a":33,"b":1,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k" ,"l" ,"m" ,"n":[],"o" ,"p":[],"q":1260407629,"r":1260595187},{"a":56,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j":2,"k":26,"l":15,"m":15,"n":{"10177679":1,"16513950":1,"260548988":1,"28364441":1,"361486206":1,"3783771":1,"41892699":1,"532102" ,"538815525":1,"649460555":1,"8374675":1},"o" ,"p":[],"q":1260346320,"r":1260461583},{"a":106,"b":6,"c" ,"d" ,"e":1,"f" ,"g" ,"h":1,"i":100,"j" ,"k":28,"l":16,"m":19,"n":{"110933010":1,"260548988":1,"3663649":1,"39206992":1,"41892699" ,"43477953":1,"63322968" ,"649460555" ,"75031690" },"o" ,"p":[],"q":1260407621,"r":1260600939}],"items":{"1":{"itemId":1},"2":{"itemId":98},"3":{"itemId":215},"4":{"itemId":100},"8":{"itemId":80003},"9":{"itemId":90001}},"user":{"healthMode":{"serverTime":1260601148,"set" ,"valid" },"pf":1}}
best regard!
robustwell
|
|
|
|

|
Thanks very much for making this useful library available.
I've found that JSON Spirit can't correctly handle the double numbers.
I have in JSON file:
{
"ground water volume flow rate" : 1234567890.123456789,
}
I read this value with:
...
jsonObj.at("ground water volume flow rate").get_real();
...
The number that I get is: 1.23457e+09
It looks like JSON Spirit handle the double numbers as float numbers (cuts till 6 decimal digits).
Is it possibe to get numbers as double?
Thanks, Tatjana
|
|
|
|

|
Thanks very much for making this library available, I've found it extraordinarily useful.
I've found that JSON Spirit can't correctly handle multiple top-level objects in a stream unless they are separated by at least one character. I'm not sure if this is a limitation of JSON Spirit or Boost. Is this a known bug or requirement? Is there any easy way around it? I'm using the latest release of JSON Spirit (4.02) and Boost IOstreams 1.40.0.1.
Example program:
#include "json_spirit.h"
#include <sstream>
#include <string>
int main(int argc, char **argv) {
std::string s = argv[1];
std::istringstream str(s);
json_spirit::Value v;
bool succ = json_spirit::read(str, v);
assert(succ);
printf("Parsed: %s\n", json_spirit::write(v).c_str());
succ = json_spirit::read(str, v);
assert(succ);
printf("Parsed: %s\n", json_spirit::write(v).c_str());
}
Example output:
$ ./simple_test "{\"test\":1}{\"test\":2}"
Parsed: {"test":1}
Parsed: "test"
./simple_test "{\"test\":1} {\"test\":2}"
Parsed: {"test":1}
Parsed: {"test":2}
Only the second run parsed it correctly, presumably because there is a space between the two objects.
Any guidance would be much appreciated. Thanks!
Jeremy
|
|
|
|

|
Thanks for the great library; it seems to have everything I need.
For your information, I am using boost 1.80, and everything works fine. (In case you want to update the opening paragraph). I have successfully compiled and linked it into a project (and I ran your test files, which came out successful.)
Edit: I'm using Visual Studio 2008, Express Edition.
|
|
|
|

|
The following can be added to the CMakeLists.txt in order to add CPack packaging and a "make install" target.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f141931..f897f1c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,3 +3,20 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(json_spirit)
SUBDIRS(json_spirit json_demo json_map_demo json_test)
INCLUDE_DIRECTORIES(json_spirit)
+
+
+INSTALL(
+ FILES
+ ${CMAKE_SOURCE_DIR}/json_spirit/json_spirit.h
+ ${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_reader.h
+ ${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_utils.h
+ ${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_value.h
+ ${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_writer.h
+ DESTINATION include)
+
+INSTALL(
+ FILES
+ ${CMAKE_BINARY_DIR}/json_spirit/libjson_spirit.a
+ DESTINATION lib)
+
+INCLUDE(CPack)
|
|
|
|

|
Hi,
It might be nice to show how easy it is to switch between using std::vector and std::map Value implementations in your demo.
Very nice code.
-- Mark
|
|
|
|

|
The library doesn't compile under Visual C++ 2010 Beta2 without some changes. All the errors consist mostly of conflicts between new stuff in std:: and the stuff in boost::, since you are using namespace std; and using namespace boost; in one of the files. The fix consists of dropping the using namespace directives and replcaing them by usings specific for the types you're using. In addition, the binds need to be explicitly qualified because it still conflicts with std due to ATL on the placeholders I believe. Should be simple fixes.
Thank you for writing this great, reliable and readable library. =)
|
|
|
|

|
Hi,
at first i would like to thank you for your work with this parser. It is really nice.
However, i have some Questions which you could hopefully answer.
If i have a json Object and want to change a deeper Property directly, it is hard work.
Example json-Object:
[
{},
{
'first':
{
'firstfirst':
{
'firstfirstfirst':
{
'property' : 'abc'
}
}
}
},
{}
]
Currently i have to do something like this, if i want to change the value of property:
json_spirit::mValue v;
json_spirit::read("[{},{'first':{'firstfirst':{'firstfirstfirst':{'property':'abc'}}}},{}]",v);
json_spirit::mObject f, ff, fff;
json_spirit::mArray a;
std::string s, s2="def";
a = v.get_array();
f = a.at(1).get_obj();
ff = f["firstfirst"].get_obj();
fff = ff["firstfirstfirst"].get_obj();
if (fff["property"].get_str() != s2)
{
fff["property"] = s2;
}
ff["firstfirstfirst"] = fff;
f["firstfirst"] = ff;
a[1] = f;
s = json_spirit::write_formatted(f);
It would be nice if i could get a pointer or a reference to fff, so i could change it directly so i do not have to put everything back.
Or is there already a chance to change a Value or Object directly?
Thanks, Jens.
|
|
|
|

|
I'm currently working with the 2.06 codebase and don't want to go through the pain of upgrading to the latest just yet. The issue I have is I can't specify information as hex. e.g.:
{ "Id": \u0004 }
Json.org implies this is legal but when I try to pass it to JSON Spirit I get Invalid JSON Structure. Can you do a quick test and see if that is still the result in 4.02?
|
|
|
|

|
Is it possible to get this library wrapped in a dll ( or just a project to generate a dll)?
The library is quite large and getting bigger for static linking.
Thanks.
habiria
|
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A C++ JSON parser/generator written using Boost::spirit
| Type | Article |
| Licence | MIT |
| First Posted | 15 Aug 2007 |
| Views | 754,212 |
| Downloads | 8,776 |
| Bookmarked | 187 times |
|
|