2 #include "../csm/csm_all.h" 6 int main(
int argc,
const char * argv[]) {
9 const char*input_filename;
10 const char*output_filename;
15 options_string(ops,
"in", &input_filename,
"stdin",
"input file (JSON)");
16 options_string(ops,
"out", &output_filename,
"stdout",
"output file (JSON)");
17 options_int(ops,
"exit_on_error", &exit_on_error, 0,
"if true, exit if object has no field");
18 options_string(ops,
"field", &field,
"field_name",
"field to extract from structure");
21 sm_info(
"Extracts a field from JSON object." 30 if(!input_stream || !output_stream)
return -1;
38 if(feof(input_stream))
break;
39 sm_error(
"Error while reading stream.\n");
46 sm_error(
"object #%d: field '%s' not found in structure.\n", n, field);
49 sm_error(
"object #%d: field '%s' not found in structure.\n", n, field);
55 fputs(
"\n", output_stream);
66 fprintf(out,
"%d", v);
71 fprintf(out,
"%d", v);
76 fprintf(out,
"%g", v);
85 fputs(
"{object}", out);
90 for(k=0; k<len; k++) {
93 if(k!=len-1) fputs(
" ", out);
char * json_object_get_string(struct json_object *this)
int json_object_array_length(struct json_object *this)
double json_object_get_double(struct json_object *this)
void sm_set_program_name(const char *name)
enum json_type json_object_get_type(struct json_object *this)
int json_object_get_int(struct json_object *this)
FILE * open_file_for_writing(const char *filename)
struct option * options_allocate(int n)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
FILE * open_file_for_reading(const char *filename)
void options_print_help(struct option *options, FILE *f)
void sm_info(const char *msg,...)
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
JO json_read_stream(FILE *f)
struct json_object * json_object_array_get_idx(struct json_object *this, int idx)
void sm_error(const char *msg,...)
int options_parse_args(struct option *ops, int argc, const char *argv[])
boolean json_object_get_boolean(struct json_object *this)