What I noticed was that I had to make sure that the code that did the yajl_buf_load_tree was carried out before the yajl_genOpen or else it would fail. I think the issue is that once yajl_genOpen has been run the the generator handle is gGenerator whereas if yajl_genOpen hasn't be run the yajl_buf_load_tree uses an arbitrary handler to create the node, then the node can be added to the document.
So this works - getAddress is just a subprogram that returns an address and flood score as JSON in the buffer
Code: Select all
getAddress(p_buffer :p_bufferlen);
addressNode = yajl_buf_load_tree(p_buffer :p_bufferlen :errMsg);
yajl_genOpen(jsonPretty());
yajl_beginObj();
yajl_addChar('type': 'person');
yajl_addChar('name': 'Eddie');
rc = yajl_genFromNode('address'
:YAJL_object_find(addressNode: 'address'));
yajl_tree_free(addressNode);
yajl_endObj();
if (not isError);
httpStatus = 200;
else;
httpStatus = 400;
endif;
yajl_writeStdout(httpStatus:errorDescription);
Code: Select all
yajl_genOpen(jsonPretty());
yajl_beginObj();
yajl_addChar('type': 'person');
yajl_addChar('name': 'Eddie');
getAddress(p_buffer :p_bufferlen);
addressNode = yajl_buf_load_tree(p_buffer :p_bufferlen :errMsg);
rc = yajl_genFromNode('address'
:YAJL_object_find(addressNode: 'address'));
yajl_tree_free(addressNode);
yajl_endObj();
if (not isError);
httpStatus = 200;
else;
httpStatus = 400;
endif;
If it could be made to work in some fashion the advantage is that if any changes were made in the sub program then it bubbles up to the main program without major rework or recompiles. So for example in Ireland we have eventually added our version of the ZIP code called the Eircode. So in this instance we would only have to add the Eircode key :value pair into the Address node in the subprogram, it should then appear in the main program's JSON.
I'm probably not explaining myself too well - the main idea of mine is to try to modularise the JSON programs but be able to pass the JSON data between programs so they can be combined into other JSON documents.
Anyway if this is impossible I don't mind at all. And if Scott reads this - again thank you so much for a brilliant tool.
Eddie