Exemplo n.º 1
0
Status
JsonFile::save(const std::string &filename) const
{
    if (json_dump_file(root_, filename.c_str(), saveFlags))
        return ABC_ERROR(ABC_CC_JSONError, "Cannot write JSON file " + filename);
    return Status();
}
Exemplo n.º 2
0
void saveRevenueMovements(char * save_path)
{
    json_t * json_revenue = json_object();
    
    json_t * array = json_array();

    json_t * json_total = json_real(total);
    
    for (struct revenue * revenue = firstRevenueMovement; revenue!=0; revenue=revenue->next)
    {
        json_array_append(array, createRevenueArray(revenue));
    }
    
    int i  = json_object_set(json_revenue, "total", json_total);
    
    int j  = json_object_set(json_revenue, "revenue", array);
    
    if (i == -1 || j == -1)
    {
        printf("errore non è possibile scrivere il file");
    }
    
    json_dump_file(json_revenue, strcat(save_path, "/revenue.json"), JSON_INDENT(3));
    
}
Exemplo n.º 3
0
void CreateJSONMaxFeatureVector(double * MaxFeatureVector,const int bins,char * filename)
{
    json_t* corr = json_object();
    json_t* jsonFileName = json_string("MaxFeatureVector");
    json_t* featureVector = json_array();
    json_t* vectorVals;
    int i;

    // Build feature vector json array
    for (i=0; i<bins; i++)
    {
        vectorVals = json_real(MaxFeatureVector[i]);
        if (json_array_append_new(featureVector,vectorVals))
        {
            printf("Cannot append %f to json array",MaxFeatureVector[i]);
            puts(strerror(errno));
            exit(1);
        }
    }
    // add both feature vector and file name to json object
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

    json_dump_file(corr,filename,JSON_INDENT(2));


    // need to call jansson specific free
    json_object_clear(corr);

}
Exemplo n.º 4
0
static void task_populate_titledb_cache_save() {
    if(json_is_object(installedApps)) {
        mkdir(TITLEDB_CACHE_DIR, 755);

        json_dump_file(installedApps, TITLEDB_CACHE_FILE, 0);
    }
}
Exemplo n.º 5
0
static void dump_file()
{
    json_t *json;
    int result;

    result = json_dump_file(NULL, "", 0);
    if (result != -1)
        fail("json_dump_file succeeded with invalid args");

    json = json_object();
    result = json_dump_file(json, "json_dump_file.json", 0);
    if (result != 0)
        fail("json_dump_file failed");

    json_decref(json);
    remove("json_dump_file.json");
}
Exemplo n.º 6
0
void event(void) {
    json_t* object;
    json_t* array_text_list;
    json_t* array_events;

    object = json_object();

    array_events = json_array();
    json_object_set(object, "events", array_events);
    json_decref(array_events);

    for (int f = 0; f < 58; f++) {
        const TableInfo* event_info;

        event_info = &table_info_event[f];

        std::string filename = "Extracted/" + std::string(event_info->filename);

        Event event(filename.c_str(), event_info->name, event_info->offset,
                    event_info->length);

        json_t* object_event;
        json_t* json_value;

        object_event = json_object();
        json_array_append(array_events, object_event);

        json_value = json_string(event_info->name);
        json_object_set(object_event, "name", json_value);
        json_decref(json_value);

        json_value = json_string(event_info->filename);
        json_object_set(object_event, "filename", json_value);
        json_decref(json_value);

        json_value = json_integer(event_info->offset);
        json_object_set(object_event, "offset", json_value);
        json_decref(json_value);

        json_value = json_integer(event_info->length);
        json_object_set(object_event, "length", json_value);
        json_decref(json_value);

        array_text_list = json_array();
        json_object_set(object_event, "text_list", array_text_list);
        json_decref(array_text_list);

        for (std::vector<Text*>::iterator tt = event.text_data()->begin();
             tt != event.text_data()->end(); tt++) {
            Text2JSON t2json(*(*tt), array_text_list);

            t2json.output();
        }
    }

    json_dump_file(object, "event.json", JSON_INDENT(0) | JSON_PRESERVE_ORDER);
    json_decref(object);
}
Exemplo n.º 7
0
static
void save_node(uv_timer_t* timer) {
    DSLink *link = timer->loop->data;
    DSNode *node = timer->data;
    timer->data = NULL;
    json_t *json = dslink_node_serialize(link, node);
    json_dump_file(json, "saved_node.json", 0);
    json_decref(json);
}
Exemplo n.º 8
0
Arquivo: urn.c Projeto: Ba5ik7/urn
int urn_game_save(const urn_game *game) {
    int error = 0;
    char str[256];
    json_t *json = json_object();
    json_t *splits = json_array();
    int i;
    if (game->title) {
        json_object_set_new(json, "title", json_string(game->title));
    }
    if (game->attempt_count) {
        json_object_set_new(json, "attempt_count",
                            json_integer(game->attempt_count));
    }
    if (game->world_record) {
        urn_time_string_serialized(str, game->world_record);
        json_object_set_new(json, "world_record", json_string(str));
    }
    if (game->start_delay) {
        urn_time_string_serialized(str, game->start_delay);
        json_object_set_new(json, "start_delay", json_string(str));
    }
    for (i = 0; i < game->split_count; ++i) {
        json_t *split = json_object();
        json_object_set_new(split, "title",
                            json_string(game->split_titles[i]));
        urn_time_string_serialized(str, game->split_times[i]);
        json_object_set_new(split, "time", json_string(str));
        urn_time_string_serialized(str, game->best_splits[i]);
        json_object_set_new(split, "best_time", json_string(str));
        urn_time_string_serialized(str, game->best_segments[i]);
        json_object_set_new(split, "best_segment", json_string(str));
        json_array_append_new(splits, split);
    }
    json_object_set_new(json, "splits", splits);
    if (game->theme) {
        json_object_set_new(json, "theme", json_string(game->theme));
    }
    if (game->theme_variant) {
        json_object_set_new(json, "theme_variant",
                            json_string(game->theme_variant));
    }
    if (game->width) {
        json_object_set_new(json, "width", json_integer(game->width));
    }
    if (game->height) {
        json_object_set_new(json, "height", json_integer(game->height));
    }
    if (!json_dump_file(json, game->path,
                        JSON_PRESERVE_ORDER | JSON_INDENT(2))) {
        error = 1;
    }
    json_decref(json);
    return error;
}
Exemplo n.º 9
0
int ast_json_dump_new_file_format(struct ast_json *root, const char *path, enum ast_json_encoding_format format)
{
	/* Jansson's json_dump*, even though it's a read operation, isn't
	 * thread safe for concurrent reads. Locking is necessary.
	 * See http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety. */
	SCOPED_JSON_LOCK(root);
	if (!root || !path) {
		return -1;
	}
	return json_dump_file((json_t *)root, path, dump_flags(format));
}
Exemplo n.º 10
0
/**
SerializeAllToJson:
Creates a single file containing all the correlogram feature vectors and the max feature vector
    @param[in] correlograms: pointer to array of correlograms to be serialize.
    @param[in] MaxFeatureVector: array of double values containing the maximum value from every correlogram for each bin
    @param[in] bins: number of quantization bins.
    @param[in] filename: string of where to write out to.
    @param[in] numCorrelograms: the number of correlograms within correlograms

*/
void SerializeAllToJson(Correlogram ** correlograms,double* MaxFeatureVector,const int bins, char * filename,int numCorrelograms)
{
    json_t* jsonCollection = json_array();
    json_t* corr;
    json_t* jsonFileName;
    json_t* featureVector;
    json_t* vectorVals;
    int i;
    int j;

    for (j=0; j<numCorrelograms; j++)
    {
        featureVector= json_array();
        jsonFileName = json_string(correlograms[j]->fileName);
        corr= json_object();
        // Build feature vector json array
        for (i=0; i<bins; i++)
        {
            vectorVals = json_real(correlograms[j]->FeatureVector[i]);
            json_array_append_new(featureVector,vectorVals);
        }

    // add both feature vector and file name to json object
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

        json_array_append_new(jsonCollection,corr);
        free(correlograms[j]->fileName);
        free(correlograms[j]->FeatureVector);
        free(correlograms[j]);
    }
    featureVector = json_array();
    jsonFileName = json_string("MaxFeatureVector");
    corr= json_object();
    for (i=0;i<bins;i++)
    {
        vectorVals = json_real(MaxFeatureVector[i]);
        json_array_append_new(featureVector,vectorVals);
    }
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

    json_array_append_new(jsonCollection,corr);


    json_dump_file(jsonCollection,filename,JSON_INDENT(2));



    // need to call jansson specific free
    json_object_clear(corr);
}
Exemplo n.º 11
0
// Write all the configuration information availible to the previousley specified FilePath. This will contain the information of each added ConfigSection.
bool ConfigFile :: Write ()
{

	if ( json_dump_file ( RootNode, FilePath, JSON_INDENT ( 4 ) | JSON_SORT_KEYS ) == - 1 )
	{

		Log -> Log ( Logger :: kLogLevel_Warning, "JSON Write failed!\n" );
		return false;
	
	}

	return true;

};
Exemplo n.º 12
0
void net_write_json_raw(const char* name) {
    json_t *root;

    root = json_object();

    json_object_set(root, "scene", net_write_json_scene());
    json_object_set(root, "ops", net_write_json_ops());
    json_object_set(root, "ins", net_write_json_ins());
    json_object_set(root, "outs", net_write_json_outs());
    json_object_set(root, "params", net_write_json_params());
    json_object_set(root, "presets", net_write_json_presets());

    json_dump_file(root, name, JSON_INDENT(4) | JSON_PRESERVE_ORDER | JSON_ESCAPE_SLASH);
}
Exemplo n.º 13
0
/*=========================================================================*\
      Write repository to file
\*=========================================================================*/
static int _dumpRepository( const char *name )
{
  int retcode  = 0;
  size_t flags = JSON_COMPACT;
  
  DBGMSG( "Dumping persistency file: \"%s\"", name ); 

/*------------------------------------------------------------------------*\
    No name given? 
\*------------------------------------------------------------------------*/
  if( !name ) {
    logerr( "Cannot write persistent repository: no name set " );
    return -1;
  }

/*------------------------------------------------------------------------*\
    No repository in mamory? 
\*------------------------------------------------------------------------*/
  if( !jRepository ) {
    logerr( "Try to dump empty repository object." );
    return -1;
  }

/*------------------------------------------------------------------------*\
    Use toolbox function 
\*------------------------------------------------------------------------*/
#ifdef ICK_DEBUG
  flags = JSON_INDENT(2) | JSON_PRESERVE_ORDER;
#endif

  if( json_dump_file(jRepository,name,flags) ) {
    logerr( "Error writing to persistent repository \"%s\": %s ", 
                     name, strerror(errno) );
    retcode = -1;  
  }

/*------------------------------------------------------------------------*\
    Try to change file mode in any case (might conatain secret info) 
\*------------------------------------------------------------------------*/
  if( chmod(name,S_IRUSR|S_IWUSR) ) {
    logerr( "Could not chmod persistent repository \"%s\": %s ", 
                     name, strerror(errno) );
    retcode = -1; 
  }
  
/*------------------------------------------------------------------------*\
    That's all 
\*------------------------------------------------------------------------*/
  return retcode;
}
Exemplo n.º 14
0
void Config::save(const char *path)
{
    json_t* json = json_object();
    json_object_set_new(json, "useAuth", json_boolean(this->useAuth));

    if(this->useAuth)
    {
        json_object_set_new(json, "authHash", json_string(this->authHash.c_str()));
        json_object_set_new(json, "authSalt", json_string(this->authSalt.c_str()));
    }

    json_dump_file(json, path, JSON_INDENT(2));

    json_decref(json);
}
Exemplo n.º 15
0
int Patch::write(const string &file)
{
  jRoot = json_object();

  writeCommons(jRoot);
  writeColumns(jRoot, &columns);
  writeChannels(jRoot, &channels);
#ifdef WITH_VST
  writePlugins(jRoot, &masterInPlugins, PATCH_KEY_MASTER_IN_PLUGINS);
  writePlugins(jRoot, &masterOutPlugins, PATCH_KEY_MASTER_OUT_PLUGINS);
#endif

  if (json_dump_file(jRoot, file.c_str(), JSON_COMPACT) != 0) {
    gu_log("[Patch::write] unable to write patch file!\n");
    return 0;
  }
  return 1;
}
Exemplo n.º 16
0
static void session_save_plugin_state(void**)
{
    const char* filename = "t2-output/test.json";

    {
        PDSaveState saveFuncs;

        json_t* root = json_object();
        json_t* array = json_array();
        json_object_set_new(root, "plugin_data", array);

        PluginIO_initSaveJson(&saveFuncs);

        saveFuncs.privData = array;

        s_dummyPlugin.saveState(0, &saveFuncs);

        json_dump_file(root, filename, JSON_COMPACT | JSON_INDENT(4) | JSON_PRESERVE_ORDER);
    }

    {
        PDLoadState loadFuncs;

        json_error_t error;

        json_t* root = json_load_file(filename, 0, &error);

        if (!root || !json_is_object(root))
        {
            printf("JSON: Unable to open %s for read\n", filename);
            return;
        }

        json_t* pluginData = json_object_get(root, "plugin_data");
        assert_true(json_typeof(pluginData) == JSON_ARRAY);

        SessionLoadState loadState = { pluginData, (int)json_array_size(pluginData), 0 };

        PluginIO_initLoadJson(&loadFuncs);
        loadFuncs.privData = &loadState;

        s_dummyPlugin.loadState(0, &loadFuncs);
    }
}
bool TDvbJanssonParser::SetProfiles(std::string& profiles)
{
  bool ret(true);
  json_error_t error;
  json_t* json = json_loads(profiles.c_str(), 0, &error);
  if (json) {
    if (json_dump_file(json, DvbConfigProfileFile.c_str(), JSON_INDENT(2)|JSON_ENSURE_ASCII|JSON_PRESERVE_ORDER) == -1) {
      OS_LOG(DVB_ERROR,   "%s:%d: json_dump_file(%s) failed\n",
        __FUNCTION__, __LINE__, DvbConfigProfileFile.c_str());
      ret = false;
    }
    json_decref(json);
  }
  else {
    OS_LOG(DVB_ERROR,   "%s:%d: json_loads() failed, error = %s\n",
      __FUNCTION__, __LINE__, error.text);
    ret = false;
  }
  return ret;
}
Exemplo n.º 18
0
void saveLostMovements(char * save_path)
{
    json_t * json_lost = json_object();
    
    json_t * array = json_array();
    
    for (struct lost * lost = firstLostMovement; lost!=0; lost=lost->next)
    {
        json_array_append(array, createLostArray(lost));
    }
    
    int i  = json_object_set(json_lost, "lost", array);
    
    if (i == -1)
    {
        printf("errore non è possibile scrivere il file");
    }
    
    json_dump_file(json_lost, strcat(save_path, "/lost.json"), JSON_INDENT(3));
}
Exemplo n.º 19
0
static bool SaveRemoteJobDetails (RemoteServiceJob *job_p, const BlastServiceData *blast_data_p)
{
	bool success_flag = false;
	char uuid_s [UUID_STRING_BUFFER_SIZE];
	char *output_filename_s = NULL;

	ConvertUUIDToString (job_p -> rsj_job.sj_id, uuid_s);

	output_filename_s = GetLocalJobFilename (uuid_s, blast_data_p);

	if (output_filename_s)
		{
			json_error_t error;
			json_t *remote_p = NULL;

			ConvertUUIDToString (job_p -> rsj_job_id, uuid_s);

			remote_p = json_pack_ex (&error, 0, "{s:s,s:s,s:s}", JOB_REMOTE_URI_S, job_p -> rsj_uri_s, JOB_REMOTE_UUID_S, uuid_s, JOB_SERVICE_S, job_p -> rsj_service_name_s);

			if (remote_p)
				{
					int res = json_dump_file (remote_p, output_filename_s, JSON_INDENT (2));

					if (res == 0)
						{
							success_flag = true;
						}

					json_decref (remote_p);
				}		/* if (remote_p) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create remote json data, error at line %d, col %d,  \"%s\"", error.line, error.column, error.text);
				}

			FreeCopiedString (output_filename_s);
		}		/* if (output_filename_s) */

	return success_flag;
}
Exemplo n.º 20
0
/**
 * remove summary (if any) and pipe hat. This is typicaly used for simulations
 */
void ssm_pipe_hat(FILE *stream, json_t *jparameters, ssm_input_t *input, ssm_hat_t *hat, ssm_par_t *par, ssm_calc_t *calc, ssm_nav_t *nav, ssm_options_t *opts, double t)
{
    int i, index;
    double x;

    json_t *jresources = json_object_get(jparameters, "resources");
    json_t *jsummary = NULL;
    int index_summary;
	
    for(index=0; index< json_array_size(jresources); index++){
        json_t *el = json_array_get(jresources, index);

        const char* name = json_string_value(json_object_get(el, "name"));
        if (strcmp(name, "values") == 0) {
            json_t *values = json_object_get(el, "data");

            for(i=0; i<nav->theta_all->length; i++){
                x = nav->theta_all->p[i]->f_2prior(gsl_vector_get(input, nav->theta_all->p[i]->offset), hat, par, calc, t);
                json_object_set_new(values, nav->theta_all->p[i]->name, json_real(x));
            }
        } else if (strcmp(name, "summary") == 0){
	    jsummary = el;
	    index_summary = index;
	}
    }

    if(jsummary){
	json_array_remove(jresources, index_summary);       
    }

    if(strcmp(opts->next, "") != 0){
	char path[SSM_STR_BUFFSIZE];
	snprintf(path, SSM_STR_BUFFSIZE, "%s/%s%d.json", opts->root, opts->next, opts->id);
	json_dump_file(jparameters, path, JSON_INDENT(2));
    } else {
	json_dumpf(jparameters, stdout, JSON_COMPACT); printf("\n");
	fflush(stdout);	
    }
}
Exemplo n.º 21
0
//native bool:json_dump_file(Handle:hObject, const String:sFilePath[], iIndentWidth = 4, bool:bEnsureAscii = false, bool:bSortKeys = false, bool:bPreserveOrder = false);
static cell_t Native_json_dump_file(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
	json_t *object;
	Handle_t hndlObject = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlObject, htJanssonObject, &sec, (void **)&object)) != HandleError_None)
    {
        return pContext->ThrowNativeError("Invalid <Object> handle %x (error %d)", hndlObject, err);
    }

	// Param 2
	char *jsonfile;
	pContext->LocalToString(params[2], &jsonfile);
	
	char filePath[PLATFORM_MAX_PATH];
	g_pSM->BuildPath(Path_Game, filePath, sizeof(filePath), jsonfile);


	size_t flags = JSON_INDENT(params[3]);		// Param 3: iIndentWidth
	if(params[4] == 1) {						// Param 4: bEnsureAscii
		flags = flags | JSON_ENSURE_ASCII;
	}

	if(params[5] == 1) {						// Param 5: bSortKeys
		flags = flags | JSON_SORT_KEYS;
	}

	if(params[6] == 1) {						// Param 6: bPreserveOrder
		flags = flags | JSON_PRESERVE_ORDER;
	}

	// Return
	bool bSuccess = (json_dump_file(object, filePath, flags) == 0);
	return bSuccess;
}
Exemplo n.º 22
0
void rdiswindow_save (GtkMenuItem * menuItem, struct _rdiswindow * rdiswindow)
{
    GtkWidget * dialog;
    char tmp[256];

    if (rdiswindow->gui->rdis == NULL) {
        gui_console(rdiswindow->gui, "no rdis loaded");
        return;
    }

    dialog = gtk_file_chooser_dialog_new(LANG_SAVERDISFILE,
                                         GTK_WINDOW(rdiswindow->window),
                                         GTK_FILE_CHOOSER_ACTION_SAVE,
                                         GTK_STOCK_CANCEL,
                                         GTK_RESPONSE_CANCEL,
                                         GTK_STOCK_SAVE,
                                         GTK_RESPONSE_ACCEPT,
                                         NULL);

    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
    {
        char * filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));

        json_t * json = object_serialize(rdiswindow->gui->rdis);
        if (json_dump_file(json, filename, JSON_COMPACT))
            snprintf(tmp, 256, "error (json) saving file %s\n", filename);
        else
            snprintf(tmp, 256, "saved file %s\n", filename);

        gui_console(rdiswindow->gui, tmp);

        json_decref(json);

        g_free(filename);
    }

    gtk_widget_destroy(dialog);
}
Exemplo n.º 23
0
int netloc_dc_close(netloc_data_collection_handle_t *handle)
{
    int ret;

    /*
     * Sanity Checks
     */
    if( NULL == handle ) {
        fprintf(stderr, "Error: Null handle provided\n");
        return NETLOC_ERROR;
    }

    /*
     * If read only, then just close the fd
     */
    if( handle->is_read_only ) {
        handle->is_open = false;
        return NETLOC_SUCCESS;
    }


    /******************** Node and Edge Data **************************/

    json_object_set_new(handle->node_data, JSON_NODE_FILE_NODE_INFO, handle->node_data_acc);

    /*
     * Add the edge lookup table to the node data
     */
    json_object_set_new(handle->node_data, JSON_NODE_FILE_EDGE_INFO, netloc_dt_lookup_table_t_json_encode(handle->edges, &dc_encode_edge));
    //netloc_lookup_table_pretty_print(handle->edges);

    /*
     * If creating a new file, then write out the data (Node)
     */
    ret = json_dump_file(handle->node_data, handle->filename_nodes, JSON_COMPACT);
    if( 0 != ret ) {
        fprintf(stderr, "Error: Failed to write out node JSON file!\n");
        return NETLOC_ERROR;
    }

    json_decref(handle->node_data);
    handle->node_data = NULL;


    /******************** Physical Path Data **************************/
    struct netloc_dt_lookup_table_iterator *hti = NULL;
    netloc_node_t *cur_node = NULL;

    /*
     * Add path entries to the JSON file (physical path)
     */
    hti = netloc_dt_lookup_table_iterator_t_construct(handle->node_list);
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        cur_node = (netloc_node_t*)netloc_lookup_table_iterator_next_entry(hti);
        if( NULL == cur_node ) {
            break;
        }

        json_object_set_new(handle->phy_path_data_acc,
                            cur_node->physical_id,
                            netloc_dt_node_t_json_encode_paths(cur_node, cur_node->physical_paths));
    }
    netloc_dt_lookup_table_iterator_t_destruct(hti);
    json_object_set_new(handle->phy_path_data, JSON_NODE_FILE_PATH_INFO, handle->phy_path_data_acc);

    /*
     * Write out path data
     */
    ret = json_dump_file(handle->phy_path_data, handle->filename_physical_paths, JSON_COMPACT);
    if( 0 != ret ) {
        fprintf(stderr, "Error: Failed to write out physical path JSON file!\n");
        return NETLOC_ERROR;
    }

    json_decref(handle->phy_path_data);
    handle->phy_path_data = NULL;


    /******************** Logical Path Data **************************/

    /*
     * Add path entries to the JSON file (logical path)
     */
    hti = netloc_dt_lookup_table_iterator_t_construct(handle->node_list);
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        cur_node = (netloc_node_t*)netloc_lookup_table_iterator_next_entry(hti);
        if( NULL == cur_node ) {
            break;
        }

        json_object_set_new(handle->path_data_acc,
                            cur_node->physical_id,
                            netloc_dt_node_t_json_encode_paths(cur_node, cur_node->logical_paths));
    }
    netloc_dt_lookup_table_iterator_t_destruct(hti);
    json_object_set_new(handle->path_data, JSON_NODE_FILE_PATH_INFO, handle->path_data_acc);

    /*
     * Write out path data
     */
    ret = json_dump_file(handle->path_data, handle->filename_logical_paths, JSON_COMPACT);
    if( 0 != ret ) {
        fprintf(stderr, "Error: Failed to write out logical path JSON file!\n");
        return NETLOC_ERROR;
    }

    json_decref(handle->path_data);
    handle->path_data = NULL;

    /*
     * Mark file as closed
     */
    handle->is_open = false;

    return NETLOC_SUCCESS;
}
Exemplo n.º 24
0
int main(int argc, char** argv) {
	parse_flags(argc, argv);
	init_word_frequency();

	// TODO: merge with //performance.c
	json_t* json_results = json_array();
	for (double x = FLAGS.minimum; x < FLAGS.maximum; x *= FLAGS.base) {
		const uint64_t size = round(x);
		log_info("size=%" PRIu64, size);

		struct metrics result;
		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			PMA_COUNTERS.reorganized_size = 0;
			CUCKOO_COUNTERS.inserts = 0;
			CUCKOO_COUNTERS.full_rehashes = 0;
			CUCKOO_COUNTERS.traversed_edges = 0;
			result = measure_serial(FLAGS.measured_apis[i],
					SERIAL_JUST_INSERT, size, 100);

			json_t* point = json_object();
			add_common_keys(point, "serial-insertonly", size,
					FLAGS.measured_apis[i], result);
			if (FLAGS.measured_apis[i] == &dict_cobt) {
				json_object_set_new(point, "pma_reorganized",
						json_integer(PMA_COUNTERS.reorganized_size));
			}
			if (FLAGS.measured_apis[i] == &dict_htcuckoo) {
				json_object_set_new(point, "cuckoo_inserts",
						json_integer(CUCKOO_COUNTERS.inserts));
				json_object_set_new(point, "cuckoo_full_rehashes",
						json_integer(CUCKOO_COUNTERS.full_rehashes));
				json_object_set_new(point, "cuckoo_traversed_edges",
						json_integer(CUCKOO_COUNTERS.traversed_edges));
			}
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			result = measure_serial(FLAGS.measured_apis[i],
					SERIAL_JUST_FIND, size, 100);

			json_t* point = json_object();
			add_common_keys(point, "serial-findonly", size,
					FLAGS.measured_apis[i], result);
			json_object_set_new(point, "success_percentage",
					json_integer(100));
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}
		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			result = measure_serial(FLAGS.measured_apis[i],
					SERIAL_JUST_FIND, size, 50);

			json_t* point = json_object();
			add_common_keys(point, "serial-findonly", size,
					FLAGS.measured_apis[i], result);
			json_object_set_new(point, "success_percentage",
					json_integer(50));
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}
		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			result = measure_serial(FLAGS.measured_apis[i],
					SERIAL_JUST_FIND, size, 0);

			json_t* point = json_object();
			add_common_keys(point, "serial-findonly", size,
					FLAGS.measured_apis[i], result);
			json_object_set_new(point, "success_percentage",
					json_integer(0));
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			result = measure_working_set(FLAGS.measured_apis[i], size, 1000);

			json_t* point = json_object();
			add_common_keys(point, "workingset", size,
					FLAGS.measured_apis[i], result);
			json_object_set_new(point, "working_set_size", json_integer(1000));
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			result = measure_working_set(FLAGS.measured_apis[i], size, 100000);

			json_t* point = json_object();
			add_common_keys(point, "workingset", size,
					FLAGS.measured_apis[i], result);
			json_object_set_new(point, "working_set_size", json_integer(100000));
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			const dict_api* api = FLAGS.measured_apis[i];
			if (!dict_api_allows_order_queries(api)) {
				log_info("order queries not supported by %s, "
						"skipping.", api->name);
				continue;
			}
			KSPLAY_COUNTERS.ksplay_steps = 0;
			KSPLAY_COUNTERS.composed_keys = 0;
			result = measure_ltr_scan(api, size);

			json_t* point = json_object();
			add_common_keys(point, "ltr_scan", size,
					FLAGS.measured_apis[i], result);
			if (FLAGS.measured_apis[i] == &dict_ksplay) {
				json_object_set_new(point, "ksplay_steps",
						json_integer(KSPLAY_COUNTERS.ksplay_steps));
				json_object_set_new(point, "ksplay_composed_keys",
						json_integer(KSPLAY_COUNTERS.composed_keys));
			}
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		for (int i = 0; FLAGS.measured_apis[i]; ++i) {
			// TODO: Only measure if there are enough words
			// in the file.
			result = measure_word_frequency(FLAGS.measured_apis[i],
					size);

			json_t* point = json_object();
			add_common_keys(point, "word_frequency", size,
					FLAGS.measured_apis[i], result);
			json_array_append_new(json_results, point);
			measurement_results_release(result.results);
		}

		log_verbose(1, "flushing results...");
		CHECK(!json_dump_file(json_results,
					"experiments/performance/output/results.json",
					JSON_INDENT(2)), "cannot dump results");
		log_verbose(1, "done");
	}


	deinit_word_frequency();
	json_decref(json_results);
	return 0;
}
Exemplo n.º 25
0
void ssm_pipe_theta(FILE *stream, json_t *jparameters, ssm_theta_t *theta, ssm_var_t *var, ssm_fitness_t *fitness, ssm_nav_t *nav, ssm_options_t *opts)
{
    int i, j, index;
    double x;

    json_t *jresources = json_object_get(jparameters, "resources");
    json_t *jcovariance = NULL;
    json_t *jsummary = NULL;

    for(index=0; index< json_array_size(jresources); index++){
        json_t *el = json_array_get(jresources, index);

        const char* name = json_string_value(json_object_get(el, "name"));
        if (strcmp(name, "values") == 0) {
            json_t *values = json_object_get(el, "data");

            for(i=0; i<nav->theta_all->length; i++){
                x = nav->theta_all->p[i]->f_inv(gsl_vector_get(theta, nav->theta_all->p[i]->offset_theta));
                json_object_set_new(values, nav->theta_all->p[i]->name, json_real(x));
            }

        } else if ((strcmp(name, "covariance") == 0)) {
            jcovariance = el;
	} else if ((strcmp(name, "summary") == 0)) {
	    jsummary = el;
	}
    }

    json_t *jsummarydata = json_object();
    json_object_set_new(jsummarydata, "id", json_integer(opts->id));
    json_object_set_new(jsummarydata, "AIC", isnan(fitness->AIC) ? json_null(): json_real(fitness->AIC));
    json_object_set_new(jsummarydata, "AICc", isnan(fitness->AICc) ? json_null(): json_real(fitness->AICc));
    json_object_set_new(jsummarydata, "DIC", isnan(fitness->DIC) ? json_null(): json_real(fitness->DIC));
    json_object_set_new(jsummarydata, "log_likelihood", isnan(fitness->summary_log_likelihood) ? json_null(): json_real(fitness->summary_log_likelihood));
    json_object_set_new(jsummarydata, "log_ltp", isnan(fitness->summary_log_ltp) ? json_null(): json_real(fitness->summary_log_ltp));
    json_object_set_new(jsummarydata, "sum_squares", isnan(fitness->summary_sum_squares) ? json_null(): json_real(fitness->summary_sum_squares));
    json_object_set_new(jsummarydata, "n_parameters", json_integer(nav->theta_all->length));
    json_object_set_new(jsummarydata, "n_data", json_integer(fitness->n));

    if(!jsummary){
	json_array_append_new(jresources, json_pack("{s,s,s,s,s,o}", "name", "summary", "format", "json", "data", jsummarydata));
    } else{
	json_object_set_new(jsummary, "data", jsummarydata);
    }

    if(var){
        json_t *jdata = json_object();

        for(i=0; i<nav->theta_all->length; i++){
            json_t *jrow = json_object();
            for(j=0; j<nav->theta_all->length; j++){
                x = gsl_matrix_get(var, nav->theta_all->p[i]->offset_theta, nav->theta_all->p[j]->offset_theta);
                if(x){
                    json_object_set_new(jrow, nav->theta_all->p[j]->name, json_real(x));
                }
            }
            if(json_object_size(jrow)){
                json_object_set_new(jdata, nav->theta_all->p[i]->name, jrow);
            } else {
                json_decref(jrow);
            }
        }

        if(json_object_size(jdata)){
            if(!jcovariance){
                json_array_append_new(jresources, json_pack("{s,s,s,s,s,o}", "name", "covariance", "format", "json", "data", jdata));
            } else{
                json_object_set_new(jcovariance, "data", jdata);
            }
        } else {
            json_decref(jdata);
        }
    }    
    
    if(strcmp(opts->next, "") != 0){
	char path[SSM_STR_BUFFSIZE];
	snprintf(path, SSM_STR_BUFFSIZE, "%s/%s%d.json", opts->root, opts->next, opts->id);
	json_dump_file(jparameters, path, JSON_INDENT(2));
    } else {
	json_dumpf(jparameters, stdout, JSON_COMPACT); printf("\n");
	fflush(stdout);	
    }
}
Exemplo n.º 26
0
void net_json_convert_min3(json_t* r) {
 
  // ADC has changed i/o count from [2,2] to [3,2],
  // and likewise size of byte-arry of state data.

  // there is only one ADC operator, so this isn't too bad.
  
  /// magic number based on what 0.3.x scenes looked like.
  int lastAdcIn = 29;

  json_t* ins = json_object_get(r, "ins");
  json_t* insData = json_object_get(ins, "data");
  int insCount = json_integer_value(json_object_get(ins, "count"));
  json_integer_set(json_object_get(ins, "count"), insCount + 1);

  // need to f*x 

  // all we should have to do for input nodes is: 
  // - insert a new node
  // - fix everyone's index
  json_t* o = json_object();
  json_object_set(o, "idx", json_integer(lastAdcIn));
  json_object_set(o, "name", json_string("MODE    "));
  json_object_set(o, "opIdx", json_integer(10));
  json_object_set(o, "opInIdx", json_integer(2));
  json_object_set(o, "value", json_integer(0));
  json_object_set(o, "play", json_integer(0));
  int err  = json_array_insert(insData, lastAdcIn + 1, o );

  if(err != 0) { printf(" error inserting input node in ADC op conversion."); }
  
  // loop over input nodes and fix idx fields
  for(int i=0; i<NET_INS_MAX; i++) {
    json_integer_set(json_object_get(json_array_get(insData, i), "idx"), i);
  }

  // we also have to add some dummy values to the byte array of the ADC op's state.
  json_t* ops = json_object_get(r, "ops");
  // 10 is the magic number of the ADC op in 0.3.x
  json_t* adc = json_array_get(json_object_get(ops, "data"), 10);
  // mode pickle: 2 bytes input value, zero is fine
  json_array_append(json_object_get(adc, "state"),  json_integer(0));
  json_array_append(json_object_get(adc, "state"),  json_integer(0));

  /* // copy all input nodes above this operator's... */
  /* // count down from top. src has fewer input nodes; otherwise we would lose last value. */
  /* for(int i = NET_INS_MAX - 1; i > lastAdcIn; i--) { */
  /*   // get json object at this index in node array */
  /*   json_t* dst = json_array_get(insData, i); */
  /*   json_t* src = json_array_get(insData, i - 1);     */
  /*   if(src != NULL) { */
  /*     if(dst == NULL) { */
  /* 	int err; */
  /* 	dst = json_object(); */
  /* 	json_object_set(dst, "idx", json_integer(i)); */
  /* 	err = json_array_insert(insData, i, dst); */
  /* 	if(err != 0) { printf(" error inserting input node in ADC op conversion."); } */
  /*     } */
  /*     // shallow copy ok? */
  /*     json_array_set(insData, src); */
  /*     // custom-copy, leaving idx */
  /*     /\* json_object_(dst, "name", json_object_get(src, "name")); *\/ */
  /*     /\* json_object_set(dst, "opIdx", json_object_get(src, "opIdx")); *\/ */
  /*     /\* json_object_set(dst, "opInIdx", json_object_get(src, "opInIdx")); *\/ */
  /*     /\* json_object_set(dst, "value", json_object_get(src, "value")); *\/ */
  /*     /\* json_object_set(dst, "play", json_object_get(src, "play")); *\/ */
  /*   } */
  /* } */
  /* // finally, we need to fix up the values for the new input ("mode");   */
  /* ///... FIXME */

  
  //---- -outs
  json_t* outs = json_object_get(r, "outs");
  json_t* outsData = json_object_get(outs, "data");
  // loop over all outputs and check targets
  for(int i = 0; i< NET_OUTS_MAX; i++) {
    json_t* o = json_array_get(outsData, i);
    int t = json_integer_value(json_object_get(o, "target"));
      if(t > lastAdcIn) {
	json_integer_set(json_object_get(o, "target"), t + 1);
      }
  }

  // i don't think anyone really used presets in this rev, so skipping those for now.

  // write the output of the converted json for a visual check.
  json_dump_file(r, "converted.json", JSON_INDENT(4) | JSON_PRESERVE_ORDER | JSON_ESCAPE_SLASH);
}
Exemplo n.º 27
0
bool TrafficNetwork::saveToFile(const string out_prefix, bool newWeek){
	bool everythingOK = true;
	int metric = KPH; //save in KPH such that it can be used by external tool (and be human readable)
	std::vector<long> nIds;
	long crtId;
	char crtType;
	string out_fileName = (out_prefix+"_roads_stats.json");

	json_t *root = NULL;

	if(firstSaved){
		if(fileName != ""){
			json_error_t error;

			root = json_load_file(fileName.c_str(), 0, &error);

			if(!root){
				std::cout<<std::endl<<"WARNING: while opening "<<fileName<<" at line "<<error.line<<" - "<<error.text<<std::endl;
				root= NULL;
			}

			if(!json_is_object(root)){
				std::cout<<std::endl<<"WARNING: input file "<<fileName<<" has not the correct structure - expected root to be an object"<<std::endl;
				json_decref(root);
				root = NULL;
			}

			if(!root){
				std::cout<<"File "<<fileName<<" could not be using during saving process"<<std::endl<<"\t --> reverting to saving network based on stored data (possibility for loss of positional infos)"<<std::endl;
			}
		}

		if(!root){
			root = json_object();
			if ( root ) {
				json_object_set_new(root, "metric" ,json_integer(metric));
				json_t *_nodes = json_array();
				json_t *_roads = json_array();
				for(NodeVec::iterator it= nodes.begin() ; it!=nodes.end(); ++it){
					json_t * _node = json_object();
					crtId = (*it)->getId();
					crtType = (*it)->getType();
					json_object_set_new(_node,"id",json_integer(crtId));
					json_object_set_new(_node,"type",json_integer(crtType));
					json_array_append_new(_nodes,_node);
					nIds = (*it)->getNeighborsId();
					for(std::vector<long>::iterator jt = nIds.begin(); jt != nIds.end(); ++jt){
						Road r = *((*it)->roadTo(*jt));
						json_t * _road = json_object();
						json_object_set_new(_road,"name",json_string(r.getName().c_str()));
						json_object_set_new(_road,"startId",json_integer(crtId));
						json_object_set_new(_road,"endId",json_integer(r.getEndPoint()->getId()));
						json_object_set_new(_road,"speedLimit",json_integer(r.getSpeedLimit()*3.6)); //x3.6 to go from MPS to KPH
						json_object_set_new(_road,"length",json_real(r.getLength()/1000)); // /1000 to go from M to K
						json_object_set_new(_road,"nbBands",json_integer(r.getNbBands()));

						json_array_append_new(_roads,_road);
					}
				}
				json_object_set_new(root, "nodes" ,_nodes);
				json_object_set_new(root, "roads" ,_roads);
			}else{
				std::cout<<"ERROR: Could not create 'root' during saving process"<<std::endl;
				return false;
			}

		}
	}else{
		json_error_t error;

		root = json_load_file(out_fileName.c_str(), 0, &error);

		if(!root){
			std::cout<<std::endl<<"ERROR: while opening "<<out_fileName<<" at line "<<error.line<<" - "<<error.text<<std::endl;
			root= NULL;
			return false;
		}

		if(!json_is_object(root)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - expected root to be an object"<<std::endl;
			json_decref(root);
			root = NULL;
			return false;
		}
	}

	json_t *roadsInfos;
	if(monitered){
		bool first = false;
		if(firstSaved){
			roadsInfos = json_array();
			int nbRoads = json_array_size(json_object_get(root,"roads"));
			for(int i = 0; i < nbRoads; i++){
				json_array_append_new(roadsInfos,json_object());
			}
			json_object_set(root,"roadsInfos",roadsInfos);
			json_object_set_new(root,"timePrecision",json_integer(TIME_PRECISION));
			json_object_set_new(root,"time_index",json_integer(0));
			json_object_set_new(root,"driversCount_index",json_integer(1));
			firstSaved = false;
			first = true;
		}else
			roadsInfos = json_object_get(root,"roadsInfos");
		json_t *infos;
		for(NodeVec::iterator it= nodes.begin() ; it!=nodes.end(); ++it){
			nIds = (*it)->getNeighborsId();
			for(std::vector<long>::iterator jt = nIds.begin(); jt != nIds.end(); ++jt){
				Road* r = ((*it)->roadTo(*jt));
				infos = r->getMonitor()->getInfos();
				if(first){
					json_object_update(json_array_get(roadsInfos,r->getId()),infos);
				}else{
					json_array_extend(json_object_get(json_array_get(roadsInfos,r->getId()),"data"),json_object_get(infos,"data"));
				}
				r->getMonitor()->resetInfos(newWeek);
				json_object_clear(infos);
				json_decref(infos);
			}
		}
	}

	//actually save
	if(!(json_dump_file(root,out_fileName.c_str(),JSON_COMPACT) == 0)){
	//if(!(json_dump_file(root,out_fileName.c_str(),JSON_INDENT(2)) == 0)){ //<== to have pretty JSON file
		everythingOK = false;
		std::cout<< "Could not open file : "<<out_fileName << " to write down network "<< name <<std::endl;
	}
	if(monitered){
		json_array_clear(roadsInfos);
	}
	json_object_clear(root);
	json_decref(root);
	if(newWeek){
		firstSaved = true;
	}
	return everythingOK;
}
Exemplo n.º 28
0
//  --------------------------------------------------------------------------
//  Export tree to json
char *
zgtask_tree_export_json (zgtask_tree_t *self, char *path, json_t *json, bool compact)
{
    assert (self);
    bool is_root = false;
    if (!json) {
        json = json_object ();
        is_root = true;
    }
    assert (json);

    json_t *array = NULL;
    json_t *obj_array = json_object ();
    if (!json_is_array (json)) {
        array = json_array ();
        json_object_set_new (json, "array", array);
    }
    else
        array = json;
    json_array_append (array, obj_array);


    json_object_set_new (obj_array, "name", json_string (self->name));
    zgtask_task_t *task = zgtask_tree_get_task (self);
    if (task) {
        json_t *obj_task = json_object ();
        json_object_set_new (obj_array, "task", obj_task);
        zgtask_task_export_json (task, obj_task);
    }

    zgtask_packet_t *packet = (zgtask_packet_t *) zgtask_tree_get_packet (self);
    if (packet) {
        json_t *obj_task = json_object ();
        json_object_set_new (obj_array, "packet", obj_task);
        zgtask_packet_export_json (packet, obj_task);
    }

    if (self->brother)
        zgtask_tree_export_json (self->brother, 0, array, compact);

    if (self->child)
        zgtask_tree_export_json (self->child, 0, obj_array, compact);

    //  Cleaning object array
    json_decref (obj_array);

    if (!is_root)
        return 0;

    size_t json_flag = JSON_STRICT;
    if (compact)
    	json_flag = JSON_COMPACT;

    if (path)
        json_dump_file (json, path, json_flag);

    char *json_str = json_dumps (json, json_flag);

    //  Cleaning
    json_decref (json);

    return json_str;
}
Exemplo n.º 29
0
// Fetch JSON from OpenWeatherMap
struct json_write_result *
owm_fetch_remote (const char method, const char * location, const char scale,
                  const char * file_cache_path, const char * api_key) {

    CURL * handle;
    CURLcode result;

    char * data = calloc(1, BUFFER_SIZE);
    static struct json_write_result written_result;
    written_result.data = data;
    written_result.position = 0;

    char url [256] = {'\0'};
    char * fetch_method;
    char * fetch_scale;

    switch ( method ) {
        case 'i':
            fetch_method = "id";
            break;

        default:
            fetch_method = "q";
            break;
    }

    switch ( scale ) {
        case 'i':
            fetch_scale = "imperial";
            break;

        default:
            fetch_scale = "metric";
            break;
    }

    handle = curl_easy_init();

    if ( handle ) {
        const char * provider =
            "http://api.openweathermap.org/data/2.5/weather";

        char * encoded_location = curl_easy_escape(handle, location, 0);

        snprintf(url, sizeof(url), "%s?%s=%s&units=%s&APPID=%s", provider,
                 fetch_method, encoded_location, fetch_scale, api_key);

        curl_easy_setopt(handle, CURLOPT_URL, url);
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data_buffer);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &written_result);

        result = curl_easy_perform(handle);
        if ( result != CURLE_OK ) {
            fprintf(stderr, "Failed to retrieve data (%s)\n",
                    curl_easy_strerror(result));

            curl_easy_cleanup(handle);
            curl_free(encoded_location);
            exit(1);
        }

        curl_free(encoded_location);
    }

    if ( file_cache_path ) {
        json_error_t err;
        json_t * resjson = json_loads(written_result.data, 0, &err);
        size_t flags = JSON_PRESERVE_ORDER | JSON_INDENT(2);
        if ( resjson && json_dump_file(resjson, file_cache_path, flags) == -1 ) {
            fprintf(stderr, "Error caching file\n");
            exit(1);
        }
    } curl_easy_cleanup(handle);

    return &written_result;
}
Exemplo n.º 30
0
// -------------------------------------------------------------------------------------------------
static int HandleGetJSON
(
    const char* nodePathPtr,  ///< Path to the node in the configTree.
    const char* filePathPtr   ///< Path to the file in the file system.  If NULL STDOUT is used
                              ///< instead of a file.
)
// -------------------------------------------------------------------------------------------------
{
    json_t* nodePtr = NULL;

    // Get the node path from our command line arguments.
    if (strcmp("*", nodePathPtr) == 0)
    {
        // Dump all trees
        // Create JSON root item
        json_t* rootPtr = CreateJsonNode("root", "root");
        json_t* treeListPtr = json_array();

        // Loop through the trees in the system.
        le_cfgAdmin_IteratorRef_t iteratorRef = le_cfgAdmin_CreateTreeIterator();
        while (le_cfgAdmin_NextTree(iteratorRef) == LE_OK)
        {
            // Allocate space for the tree name, plus space for a trailing :/ used when we create a
            // transaction for that tree.
            char treeName[MAX_TREE_NAME_BYTES + 2] = "";

            if (le_cfgAdmin_GetTreeName(iteratorRef, treeName, MAX_TREE_NAME_BYTES) != LE_OK)
            {
                continue;
            }

            // JSON node for the tree.
            json_t* treeNodePtr = CreateJsonNode(treeName, "tree");
            strcat(treeName, ":/");

            // Start a read transaction at the specified node path.  Then dump the value, (if any.)
            le_cfg_IteratorRef_t iterRef = le_cfg_CreateReadTxn(treeName);
            le_cfg_GoToFirstChild(iterRef);

            // Dump tree to JSON
            DumpTreeJSON(iterRef, treeNodePtr);
            le_cfg_CancelTxn(iterRef);

            json_array_append(treeListPtr, treeNodePtr);
        }
        le_cfgAdmin_ReleaseTreeIterator(iteratorRef);

        // Finalize root object...
        json_object_set_new(rootPtr, "trees", treeListPtr);
        nodePtr = rootPtr;
    }
    else
    {
        // Start a read transaction at the specified node path.  Then dump the value, (if any.)
        le_cfg_IteratorRef_t iterRef = le_cfg_CreateReadTxn(nodePathPtr);

        le_cfg_nodeType_t type = le_cfg_GetNodeType(iterRef, "");
        switch (type)
        {
            case LE_CFG_TYPE_STEM:
                {
                    char strBuffer[LE_CFG_STR_LEN_BYTES] = "";
                    char nodeType[LE_CFG_STR_LEN_BYTES] = "";
                    le_cfg_GetNodeName(iterRef, "", strBuffer, sizeof(strBuffer));

                    // If no name, we are dumping a complete tree.
                    if (strlen(strBuffer) == 0)
                    {
                        strcpy(nodeType, "tree");
                    }
                    else
                    {
                        strcpy(nodeType, NodeTypeStr(type));
                    }

                    nodePtr = CreateJsonNode(strBuffer, nodeType);
                    le_cfg_GoToFirstChild(iterRef);
                    DumpTreeJSON(iterRef, nodePtr);
                    le_cfg_GoToParent(iterRef);
                }
                break;

            default:
                nodePtr = CreateJsonNodeFromIterator(iterRef);
                break;
        }

        le_cfg_CancelTxn(iterRef);
    }

    if (nodePtr == NULL)
    {
        // Empty node
        nodePtr = json_object();
    }

    // Dump Json content
    // stdout mode?

    int result = EXIT_SUCCESS;

    if (filePathPtr == NULL)
    {
        printf("%s\n", json_dumps(nodePtr, JSON_COMPACT));
    }
    else if (json_dump_file(nodePtr, filePathPtr, JSON_COMPACT) != 0)
    {
        result = EXIT_FAILURE;
    }

    json_decref(nodePtr);
    return result;
}