Man page - bson_json_reader_t(3)
Packages contas this manual
- bson_oid_equal_unsafe(3)
- bson_string_append_c(3)
- bson_oid_init_from_string_unsafe(3)
- bson_get_micro_version(3)
- bson_steal(3)
- bson_append_array(3)
- bson_writer_get_length(3)
- bson_oid_get_time_t(3)
- bson_iter_double(3)
- bson_append_timeval(3)
- bson_iter_regex(3)
- bson_decimal128_to_string(3)
- bson_iter_dbpointer(3)
- bson_init_static(3)
- bson_reserve_buffer(3)
- bson_type_t(3)
- bson_iter_find_w_len(3)
- bson_json_opts_set_outermost_array(3)
- bson_writer_end(3)
- bson_get_minor_version(3)
- bson_destroy_with_steal(3)
- bson_json_data_reader_new(3)
- bson_strdup_printf(3)
- bson_json_reader_new(3)
- bson_iter_overwrite_bool(3)
- bson_string_truncate(3)
- bson_reader_read_func_t(3)
- bson_init(3)
- bson_reader_tell(3)
- bson_unichar_t(3)
- bson_destroy(3)
- bson_ascii_strtoll(3)
- bson_realloc_ctx(3)
- bson_copy_to(3)
- bson_append_undefined(3)
- bson_iter_key_len(3)
- bson_reader_set_destroy_func(3)
- bson_iter_document(3)
- bson_iter_init_from_data(3)
- bson_json_reader_new_from_file(3)
- bson_append_code_with_scope(3)
- bson_malloc0(3)
- bson_append_array_end(3)
- bson_context_destroy(3)
- bson_iter_timestamp(3)
- bson_append_value(3)
- bson_iter_as_double(3)
- bson_append_utf8(3)
- bson_uint32_to_string(3)
- bson_check_version(3)
- bson_compare(3)
- bson_iter_symbol(3)
- bson_reinit(3)
- bson_as_legacy_extended_json(3)
- bson_iter_utf8(3)
- bson_iter_init(3)
- bson_append_now_utc(3)
- bson_writer_t(3)
- bson_iter_as_int64(3)
- bson_iter_type(3)
- bson_strcasecmp(3)
- bson_iter_date_time(3)
- bson_append_iter(3)
- bson_reader_set_read_func(3)
- bson_array_as_relaxed_extended_json(3)
- bson_oid_compare(3)
- bson_iter_dup_utf8(3)
- bson_append_array_begin(3)
- bson_strdup(3)
- bson_string_free(3)
- bson_iter_timeval(3)
- bson_iter_find(3)
- bson_writer_begin(3)
- bson_append_int32(3)
- bson_append_code(3)
- bson_equal(3)
- bson_append_oid(3)
- bson_get_major_version(3)
- bson_value_copy(3)
- bson_append_time_t(3)
- bson_iter_overwrite_int64(3)
- bson_iter_overwrite_date_time(3)
- bson_append_symbol(3)
- bson_iter_init_from_data_at_offset(3)
- bson_iter_int64(3)
- bson_oid_init_from_string(3)
- bson_append_dbpointer(3)
- bson_has_field(3)
- bson_json_reader_new_from_fd(3)
- bson_count_keys(3)
- bson_t(3)
- bson_strncpy(3)
- bson_validate_with_error_and_offset(3)
- bson_iter_offset(3)
- bson_iter_bool(3)
- bson_init_from_json(3)
- bson_new_from_data(3)
- bson_reader_new_from_data(3)
- bson_append_document_end(3)
- bson_malloc(3)
- bson_append_bool(3)
- bson_iter_oid(3)
- bson_iter_value(3)
- bson_json_reader_t(3)
- bson_as_canonical_extended_json(3)
- bson_append_document(3)
- bson_writer_rollback(3)
- bson_oid_copy_unsafe(3)
- bson_iter_overwrite_oid(3)
- bson_new(3)
- bson_oid_hash(3)
- bson_copy_to_excluding(3)
- bson_validate_flags_t(3)
- bson_append_double(3)
- bson_append_document_begin(3)
- bson_oid_copy(3)
- bson_iter_init_find_case(3)
- bson_oid_equal(3)
- bson_value_t(3)
- bson_iter_key(3)
- bson_aligned_alloc(3)
- bson_reader_destroy(3)
- bson_sized_new(3)
- bson_iter_init_find_w_len(3)
- bson_json_opts_t(3)
- bson_iter_array(3)
- bson_array_as_legacy_extended_json(3)
- bson_reader_read(3)
- bson_append_date_time(3)
- bson_iter_codewscope(3)
- bson_writer_destroy(3)
- bson_strdupv_printf(3)
- bson_iter_code(3)
- bson_iter_overwrite_int32(3)
- bson_utf8_get_char(3)
- bson_string_t(3)
- bson_memory(3)
- bson_zero_free(3)
- bson_validate(3)
- bson_append_regex(3)
- bson_set_error(3)
- bson_as_json(3)
- bson_copy(3)
- bson_decimal128_t(3)
- bson_reference(3)
- bson_array_as_json(3)
- bson_context_t(3)
- bson_get_version(3)
- bson_iter_binary(3)
- bson_iter_int32(3)
- bson_iter_find_descendant(3)
- bson_vsnprintf(3)
- bson_reader_new_from_fd(3)
- bson_json_mode_t(3)
- bson_visitor_t(3)
- bson_append_minkey(3)
- bson_array_as_canonical_extended_json(3)
- bson_get_monotonic_time(3)
- bson_append_binary(3)
- bson_string_append(3)
- bson_strfreev(3)
- bson_reader_new_from_handle(3)
- bson_string_append_unichar(3)
- bson_iter_as_bool(3)
- bson_subtype_t(3)
- bson_utf8_next_char(3)
- bson_utf8_escape_for_json(3)
- bson_append_timestamp(3)
- bson_oid_to_string(3)
- bson_iter_decimal128(3)
- bson_character_and_string_routines(3)
- bson_get_data(3)
- bson_writer_new(3)
- bson_json_opts_destroy(3)
- bson_reader_reset(3)
- bson_oid_init_from_data(3)
- bson_free(3)
- bson_utf8_from_unichar(3)
- bson_value_destroy(3)
- bson_oid_is_valid(3)
- bson_reader_new_from_file(3)
- bson_oid_compare_unsafe(3)
- bson_strndup(3)
- bson_array_builder_t(3)
- bson_append_null(3)
- bson_json_opts_new(3)
- bson_string_append_printf(3)
- bson_utf8_validate(3)
- bson_context_new(3)
- bson_iter_overwrite_double(3)
- bson_append_maxkey(3)
- bson_error_t(3)
- bson_iter_find_case(3)
- bson_mem_restore_vtable(3)
- bson_iter_overwrite_timestamp(3)
- bson_new_from_json(3)
- bson_oid_hash_unsafe(3)
- bson_append_regex_w_len(3)
- bson_iter_recurse(3)
- bson_append_int64(3)
- bson_reader_t(3)
- bson_oid_get_time_t_unsafe(3)
- bson_aligned_alloc0(3)
- bson_new_from_buffer(3)
- bson_copy_to_excluding_noinit_va(3)
- bson_version(3)
- bson_string_new(3)
- bson_validate_with_error(3)
- bson_json_data_reader_ingest(3)
- bson_strnlen(3)
- bson_iter_next(3)
- bson_realloc(3)
- bson_oid_init_sequence(3)
- bson_decimal128_from_string_w_len(3)
- bson_as_json_with_opts(3)
- bson_concat(3)
- bson_oid_t(3)
- bson_strerror_r(3)
- bson_reader_destroy_func_t(3)
- bson_snprintf(3)
- bson_as_relaxed_extended_json(3)
- bson_mem_set_vtable(3)
- bson_oid_init(3)
- bson_iter_init_find(3)
- bson_context_get_default(3)
- bson_isspace(3)
- bson_decimal128_from_string(3)
- bson_iter_visit_all(3)
- bson_iter_t(3)
- bson_copy_to_excluding_noinit(3)
- bson_append_decimal128(3)
- bson_realloc_func(3)
- bson_json_reader_destroy(3)
- bson_iter_overwrite_decimal128(3)
- bson_iter_time_t(3)
- bson_json_reader_read(3)
Package: libbson-doc
apt-get install libbson-doc
apt-get install libbson-doc
Manuals in package:
Documentations in package:
Manual
| BSON_JSON_READER_T(3) | libbson | BSON_JSON_READER_T(3) |
Bulk JSON to BSON conversion
SYNOPSIS
#include <bson/bson.h>
typedef struct _bson_json_reader_t bson_json_reader_t;
typedef enum {
BSON_JSON_ERROR_READ_CORRUPT_JS = 1,
BSON_JSON_ERROR_READ_INVALID_PARAM,
BSON_JSON_ERROR_READ_CB_FAILURE,
} bson_json_error_code_t;
DESCRIPTION
The bson_json_reader_t structure is used for reading a sequence of JSON documents and transforming them to bson_t documents.
This can often be useful if you want to perform bulk operations that are defined in a file containing JSON documents.
TIP:
bson_json_reader_t works upon JSON documents
formatted in MongoDB extended JSON format.
EXAMPLE
/*
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ /*
* This program will print each JSON document contained in the provided files
* as a BSON string to STDOUT.
*/ #include <bson/bson.h> #include <stdlib.h> #include <stdio.h> int main (int argc, char *argv[]) {
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;
}
/*
* Process command line arguments expecting each to be a filename.
*/
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;
}
}
/*
* 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);
}
bson_json_reader_destroy (reader);
bson_destroy (&doc);
}
return 0; }
AUTHOR
MongoDB, Inc
COPYRIGHT
2009-present, MongoDB, Inc.
| December 18, 2025 | 1.30.4 |