diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt
index a6a9f337e..32e4ebbe5 100644
--- a/src/libbson/CMakeLists.txt
+++ b/src/libbson/CMakeLists.txt
@@ -298,9 +298,11 @@ if (ENABLE_EXAMPLES)
       target_link_libraries (bson-metrics m)
       add_example (bson-streaming-reader examples/bson-streaming-reader.c)
    endif ()
+   set_target_properties (bson-metrics PROPERTIES LINK_FLAGS -fsanitize=address,fuzzer)
    add_example (bson-to-json examples/bson-to-json.c)
    add_example (bson-validate examples/bson-validate.c)
    add_example (json-to-bson examples/json-to-bson.c)
+   set_target_properties (json-to-bson PROPERTIES LINK_FLAGS -fsanitize=address,fuzzer)
    add_example (bson-check-depth examples/bson-check-depth.c)
 endif () # ENABLE_EXAMPLES
 
diff --git a/src/libbson/examples/bson-metrics.c b/src/libbson/examples/bson-metrics.c
index 9eeb94192..4320785ae 100644
--- a/src/libbson/examples/bson-metrics.c
+++ b/src/libbson/examples/bson-metrics.c
@@ -210,110 +210,83 @@ bson_metrics (const bson_t *bson, size_t *length, void *data)
 }
 
 int
-main (int argc, char *argv[])
+LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
 {
    bson_reader_t *reader;
    const bson_t *b;
-   bson_error_t error;
-   const char *filename;
-   int i, j;
+   int j;
    double dtime_before, dtime_after, dtime_delta;
    uint64_t aggregate_count;
    off_t mark;
 
-   /*
-    * Print program usage if no arguments are provided.
-    */
-   if (argc == 1) {
-      fprintf (stderr, "usage: %s FILE...\n", argv[0]);
-      return 1;
+   reader = bson_reader_new_from_data (Data, Size);
+
+   state = initial_state;
+   dtime_before = dtimeofday ();
+   mark = 0;
+   while ((b = bson_reader_read (reader, NULL))) {
+      off_t pos = bson_reader_tell (reader);
+      state.doc_size_max = BSON_MAX (pos - mark, state.doc_size_max);
+      mark = pos;
+      bson_metrics (b, NULL, &state);
    }
+   dtime_after = dtimeofday ();
+   dtime_delta = BSON_MAX (dtime_after - dtime_before, 0.000001);
+   state.bson_type_metrics[BSON_TYPE_MAXKEY].description = "Max key";
+   state.bson_type_metrics[BSON_TYPE_MINKEY].description = "Min key";
+   aggregate_count = state.bson_type_metrics[BSON_TYPE_DOCUMENT].count +
+                     state.bson_type_metrics[BSON_TYPE_ARRAY].count;
+   qsort (state.bson_type_metrics,
+          256,
+          sizeof (bson_type_metrics_t),
+          compar_bson_type_metrics);
+
+   FILE *devnull = fopen("/dev/null", "w");
+   fprintf (devnull, "\n  {\n");
+   fprintf (devnull, "    \"secs\": %.2f,\n", dtime_delta);
+   fprintf (devnull, "    \"docs_per_sec\": %" PRIu64 ",\n",
+           (uint64_t) floor (state.doc_count / dtime_delta));
+   fprintf (devnull, "    \"docs\": %" PRIu64 ",\n", state.doc_count);
+   fprintf (devnull, "    \"elements\": %" PRIu64 ",\n", state.element_count);
+   fprintf (devnull, "    \"elements_per_doc\": %" PRIu64 ",\n",
+           (uint64_t) floor ((double) state.element_count /
+                             (double) BSON_MAX (state.doc_count, 1)));
+   fprintf (devnull, "    \"aggregates\": %" PRIu64 ",\n", aggregate_count);
+   fprintf (devnull, "    \"aggregates_per_doc\": %" PRIu64 ",\n",
+           (uint64_t) floor ((double) aggregate_count /
+                             (double) BSON_MAX (state.doc_count, 1)));
+   fprintf (devnull, "    \"degree\": %" PRIu64 ",\n",
+           (uint64_t) floor (
+              (double) state.element_count /
+              ((double) BSON_MAX (state.doc_count + aggregate_count, 1))));
+   fprintf (devnull, "    \"doc_size_max\": %" PRIu64 ",\n", state.doc_size_max);
+   fprintf (devnull, "    \"doc_size_average\": %" PRIu64 ",\n",
+           (uint64_t) floor ((double) bson_reader_tell (reader) /
+                             (double) BSON_MAX (state.doc_count, 1)));
+   fprintf (devnull, "    \"key_size_average\": %" PRIu64 ",\n",
+           (uint64_t) floor ((double) state.key_size_tally /
+                             (double) BSON_MAX (state.element_count, 1)));
+   fprintf (devnull, "    \"string_size_average\": %" PRIu64 ",\n",
+           (uint64_t) floor (
+              (double) state.utf8_size_tally /
+              (double) BSON_MAX (
+                 state.bson_type_metrics[BSON_TYPE_UTF8].count, 1)));
+   fprintf (devnull, "    \"percent_by_type\": {\n");
+   for (j = 0; state.bson_type_metrics[j].count > 0; j++) {
+      bson_type_metrics_t bson_type_metrics = state.bson_type_metrics[j];
+      fprintf (devnull, "      \"%s\": %" PRIu64 ",\n",
+              bson_type_metrics.description,
+              (uint64_t) floor ((double) bson_type_metrics.count * 100.0 /
+                                (double) BSON_MAX (state.element_count, 1)));
+   }
+   fprintf (devnull, "    }\n");
+   fprintf (devnull, "  }");
+   fclose (devnull);
 
    /*
-    * Process command line arguments expecting each to be a filename.
+    * Cleanup after our reader, which closes the file descriptor.
     */
-   printf ("[");
-   for (i = 1; i < argc; i++) {
-      if (i > 1)
-         printf (",");
-      filename = argv[i];
-
-      /*
-       * Initialize a new reader for this file descriptor.
-       */
-      if (!(reader = bson_reader_new_from_file (filename, &error))) {
-         fprintf (
-            stderr, "Failed to open \"%s\": %s\n", filename, error.message);
-         continue;
-      }
-
-      state = initial_state;
-      dtime_before = dtimeofday ();
-      mark = 0;
-      while ((b = bson_reader_read (reader, NULL))) {
-         off_t pos = bson_reader_tell (reader);
-         state.doc_size_max = BSON_MAX (pos - mark, state.doc_size_max);
-         mark = pos;
-         bson_metrics (b, NULL, &state);
-      }
-      dtime_after = dtimeofday ();
-      dtime_delta = BSON_MAX (dtime_after - dtime_before, 0.000001);
-      state.bson_type_metrics[BSON_TYPE_MAXKEY].description = "Max key";
-      state.bson_type_metrics[BSON_TYPE_MINKEY].description = "Min key";
-      aggregate_count = state.bson_type_metrics[BSON_TYPE_DOCUMENT].count +
-                        state.bson_type_metrics[BSON_TYPE_ARRAY].count;
-      qsort (state.bson_type_metrics,
-             256,
-             sizeof (bson_type_metrics_t),
-             compar_bson_type_metrics);
-
-      printf ("\n  {\n");
-      printf ("    \"file\": \"%s\",\n", filename);
-      printf ("    \"secs\": %.2f,\n", dtime_delta);
-      printf ("    \"docs_per_sec\": %" PRIu64 ",\n",
-              (uint64_t) floor (state.doc_count / dtime_delta));
-      printf ("    \"docs\": %" PRIu64 ",\n", state.doc_count);
-      printf ("    \"elements\": %" PRIu64 ",\n", state.element_count);
-      printf ("    \"elements_per_doc\": %" PRIu64 ",\n",
-              (uint64_t) floor ((double) state.element_count /
-                                (double) BSON_MAX (state.doc_count, 1)));
-      printf ("    \"aggregates\": %" PRIu64 ",\n", aggregate_count);
-      printf ("    \"aggregates_per_doc\": %" PRIu64 ",\n",
-              (uint64_t) floor ((double) aggregate_count /
-                                (double) BSON_MAX (state.doc_count, 1)));
-      printf ("    \"degree\": %" PRIu64 ",\n",
-              (uint64_t) floor (
-                 (double) state.element_count /
-                 ((double) BSON_MAX (state.doc_count + aggregate_count, 1))));
-      printf ("    \"doc_size_max\": %" PRIu64 ",\n", state.doc_size_max);
-      printf ("    \"doc_size_average\": %" PRIu64 ",\n",
-              (uint64_t) floor ((double) bson_reader_tell (reader) /
-                                (double) BSON_MAX (state.doc_count, 1)));
-      printf ("    \"key_size_average\": %" PRIu64 ",\n",
-              (uint64_t) floor ((double) state.key_size_tally /
-                                (double) BSON_MAX (state.element_count, 1)));
-      printf ("    \"string_size_average\": %" PRIu64 ",\n",
-              (uint64_t) floor (
-                 (double) state.utf8_size_tally /
-                 (double) BSON_MAX (
-                    state.bson_type_metrics[BSON_TYPE_UTF8].count, 1)));
-      printf ("    \"percent_by_type\": {\n");
-      for (j = 0; state.bson_type_metrics[j].count > 0; j++) {
-         bson_type_metrics_t bson_type_metrics = state.bson_type_metrics[j];
-         printf ("      \"%s\": %" PRIu64 ",\n",
-                 bson_type_metrics.description,
-                 (uint64_t) floor ((double) bson_type_metrics.count * 100.0 /
-                                   (double) BSON_MAX (state.element_count, 1)));
-      }
-      printf ("    }\n");
-      printf ("  }");
-
-      /*
-       * Cleanup after our reader, which closes the file descriptor.
-       */
-      bson_reader_destroy (reader);
-   }
-   printf ("\n]\n");
+   bson_reader_destroy (reader);
 
    return 0;
 }
diff --git a/src/libbson/examples/json-to-bson.c b/src/libbson/examples/json-to-bson.c
index 7339d2d2c..4851e67a3 100644
--- a/src/libbson/examples/json-to-bson.c
+++ b/src/libbson/examples/json-to-bson.c
@@ -31,61 +31,43 @@
 #endif
 
 int
-main (int argc, char *argv[])
+LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
 {
    bson_json_reader_t *reader;
    bson_error_t error;
-   const char *filename;
    bson_t doc = BSON_INITIALIZER;
-   int i;
    int b;
 
-   /*
-    * Print program usage if no arguments are provided.
-    */
-   if (argc == 1) {
-      fprintf (stderr, "usage: %s FILE...\n", argv[0]);
-      return 1;
-   }
+   FILE *tmp = tmpfile ();
+   fwrite (Data, Size, 1, tmp);
+   fflush (tmp);
+   int fd = fileno (tmp);
+   fseek (tmp, 0, SEEK_SET);
+   fsync (fd);
+   reader = bson_json_reader_new_from_fd (fd, false);
 
    /*
-    * Process command line arguments expecting each to be a filename.
+    * Convert each incoming document to BSON and print to /dev/null.
     */
-   for (i = 1; i < argc; i++) {
-      filename = argv[i];
-
-      /*
-       * Open the filename provided in command line arguments.
-       */
-      if (0 == strcmp (filename, "-")) {
-         reader = bson_json_reader_new_from_fd (STDIN_FILENO, false);
-      } else {
-         if (!(reader = bson_json_reader_new_from_file (filename, &error))) {
-            fprintf (
-               stderr, "Failed to open \"%s\": %s\n", filename, error.message);
-            continue;
-         }
+   FILE *devnull = fopen("/dev/null", "w");
+   while ((b = bson_json_reader_read (reader, &doc, &error))) {
+      if (b < 0) {
+         fprintf (stderr, "Error in json parsing:\n%s\n", error.message);
+         /* abort (); */ goto end;
       }
 
-      /*
-       * Convert each incoming document to BSON and print to stdout.
-       */
-      while ((b = bson_json_reader_read (reader, &doc, &error))) {
-         if (b < 0) {
-            fprintf (stderr, "Error in json parsing:\n%s\n", error.message);
-            abort ();
-         }
-
-         if (fwrite (bson_get_data (&doc), 1, doc.len, stdout) != doc.len) {
-            fprintf (stderr, "Failed to write to stdout, exiting.\n");
-            exit (1);
-         }
-         bson_reinit (&doc);
+      if (fwrite (bson_get_data (&doc), 1, doc.len, devnull) != doc.len) {
+         fprintf (stderr, "Failed to write to /dev/null, exiting.\n");
+         /* exit (1); */ goto end;
       }
-
-      bson_json_reader_destroy (reader);
-      bson_destroy (&doc);
+      bson_reinit (&doc);
    }
 
+end:
+   bson_json_reader_destroy (reader);
+   bson_destroy (&doc);
+   fclose (devnull);
+   fclose (tmp);
+
    return 0;
 }
