diff --git a/lib/formats/json.cpp b/lib/formats/json.cpp index 086738e22..df09b2dd1 100644 --- a/lib/formats/json.cpp +++ b/lib/formats/json.cpp @@ -54,11 +54,15 @@ static json_t * json_pack_timestamps(struct io *io, struct sample *smp) { json_t *json_ts = json_object(); - if (io->flags & smp->flags & SAMPLE_HAS_TS_ORIGIN) - json_object_set(json_ts, "origin", json_pack("[ I, I ]", smp->ts.origin.tv_sec, smp->ts.origin.tv_nsec)); + if (io->flags & SAMPLE_HAS_TS_ORIGIN) { + if (smp->flags & SAMPLE_HAS_TS_ORIGIN) + json_object_set(json_ts, "origin", json_pack("[ I, I ]", smp->ts.origin.tv_sec, smp->ts.origin.tv_nsec)); + } - if (io->flags & smp->flags & SAMPLE_HAS_TS_RECEIVED) - json_object_set(json_ts, "received", json_pack("[ I, I ]", smp->ts.received.tv_sec, smp->ts.received.tv_nsec)); + if (io->flags & SAMPLE_HAS_TS_RECEIVED) { + if (smp->flags & SAMPLE_HAS_TS_RECEIVED) + json_object_set(json_ts, "received", json_pack("[ I, I ]", smp->ts.received.tv_sec, smp->ts.received.tv_nsec)); + } return json_ts; } @@ -101,13 +105,15 @@ static int json_pack_sample(struct io *io, json_t **j, struct sample *smp) json_smp = json_pack_ex(&err, 0, "{ s: o }", "ts", json_pack_timestamps(io, smp)); - if (io->flags & smp->flags & SAMPLE_HAS_SEQUENCE) { - json_t *json_sequence = json_integer(smp->sequence); + if (io->flags & SAMPLE_HAS_SEQUENCE) { + if (smp->flags & SAMPLE_HAS_SEQUENCE) { + json_t *json_sequence = json_integer(smp->sequence); - json_object_set(json_smp, "sequence", json_sequence); + json_object_set(json_smp, "sequence", json_sequence); + } } - if (io->flags & smp->flags & SAMPLE_HAS_DATA) { + if (io->flags & SAMPLE_HAS_DATA) { json_t *json_data = json_array(); for (unsigned i = 0; i < smp->length; i++) {