diff --git a/c/cli/mlrcli.c b/c/cli/mlrcli.c index 7923bb7e4..3c5ea649d 100644 --- a/c/cli/mlrcli.c +++ b/c/cli/mlrcli.c @@ -329,8 +329,6 @@ static void main_usage_data_format_options(FILE* o, char* argv0) { fprintf(o, " e.g. '{\"a\":{\"b\":3}}' becomes a:b => 3 for\n"); fprintf(o, " non-JSON formats. Defaults to %s.\n", DEFAULT_JSON_FLATTEN_SEPARATOR); - // xxx fix this cmt once lrec_reader_stdio_json is complete - fprintf(o, " NOTE: --json and --ijson are currently under construction, but --ojson works.\n"); fprintf(o, "\n"); fprintf(o, " -p is a keystroke-saver for --nidx --fs space --repifs\n"); fprintf(o, "\n"); diff --git a/c/input/lrec_reader_mmap_json.c b/c/input/lrec_reader_mmap_json.c index 6781bc939..5387fb814 100644 --- a/c/input/lrec_reader_mmap_json.c +++ b/c/input/lrec_reader_mmap_json.c @@ -143,13 +143,16 @@ static void lrec_reader_mmap_json_sof(void* pvstate, void* pvhandle) { parsed_top_level_json = json_parse_ex(item_start, length, error_buf, &item_start, &settings); if (parsed_top_level_json == NULL) { - fprintf(stderr, "Unable to parse JSON data: %s\n", error_buf); + fprintf(stderr, "%s: Unable to parse JSON data: %s\n", error_buf, MLR_GLOBALS.argv0); exit(1); } // The lrecs have their string pointers pointing into the parsed-JSON objects (for // efficiency) so it's important we not free the latter until our free method. - reference_json_objects_as_lrecs(pstate->precords, parsed_top_level_json, pstate->json_flatten_separator); + if (!reference_json_objects_as_lrecs(pstate->precords, parsed_top_level_json, pstate->json_flatten_separator)) { + fprintf(stderr, "%s: Unable to parse JSON data.\n", MLR_GLOBALS.argv0); + exit(1); + } if (item_start == NULL) break; diff --git a/c/mapping/mapper_reshape.c b/c/mapping/mapper_reshape.c index 98af5f8cd..c5b892409 100644 --- a/c/mapping/mapper_reshape.c +++ b/c/mapping/mapper_reshape.c @@ -294,8 +294,9 @@ static sllv_t* mapper_reshape_wide_to_long_no_regex_process(lrec_t* pinrec, cont for (sllse_t* pe = pstate->input_field_names->phead; pe != NULL; pe = pe->pnext) { char* key = pe->value; char* value = lrec_get(pinrec, key); - if (value != NULL) - lhmss_put(pairs, key, value, NO_FREE); + if (value != NULL) { + lhmss_put(pairs, mlr_strdup_or_die(key), mlr_strdup_or_die(value), FREE_ENTRY_KEY|FREE_ENTRY_VALUE); + } } // Unset the lrec keys after iterating over them, rather than during @@ -332,7 +333,8 @@ static sllv_t* mapper_reshape_wide_to_long_regex_process(lrec_t* pinrec, context for (sllve_t* pf = pstate->input_field_regexes->phead; pf != NULL; pf = pf->pnext) { regex_t* pregex = pf->pvvalue; if (regmatch_or_die(pregex, pe->key, 0, NULL)) { - lhmss_put(pairs, pe->key, pe->value, NO_FREE); + lhmss_put(pairs, mlr_strdup_or_die(pe->key), mlr_strdup_or_die(pe->value), + FREE_ENTRY_KEY|FREE_ENTRY_VALUE); break; } } diff --git a/c/todo.txt b/c/todo.txt index 33d88a228..cc5a611a0 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -61,8 +61,12 @@ TOP-OF-LIST SUMMARY TOP-OF-LIST DETAILS * JSON I/O: + ! string-preservation for doubles ! + ! UT ! + ! mlr --json reshape -i x,y -o item,value rec.json + ! acknowledgement to mld: https://github.com/udp/json-parser - ! stdio version. & prefer stremable version with fgetc rather than pointer-math. + o wishlist: streamable version with fgetc rather than pointer-math. - on output, check 1st if mlhmmv is necessary? or just always? - cover x 2 - define 'tabular JSON' by example @ mld @@ -70,16 +74,9 @@ TOP-OF-LIST DETAILS - programmable allow-this-on-input flag - programmable allow-this-on-output flag - programmable flatten-separator - ? or support multi-level lrecs?? o hp re :) ! JSON/join UT. both/left/right json cases. - o bug: - - $ mlr --jlistwrap --jvstack --json cat ~/bak/bmx/bookmarks-2016-02-02.json - mlr: found array item within JSON object. This is valid but unmillerable JSON. - ] - ? env vars?? * doc: