Bson to byte array golang. fileContent = fileData; this. return buffer, nil. var result uint8. createWriter(stream). On this page. mongoSession := ConnectDb() Jan 17, 2019 · so it can't be a loop through values. 3. for _, b := range mei {. WriteFile function, which accepts a bytes as its Sep 27, 2023 · err := json. g. This method allows you to specify the encoding of the Apr 12, 2024 · Package bsoncodec provides a system for encoding values to BSON representations and decoding values from BSON representations. So if you need to add more elemnets, you can not append. Using json. s = append(s, strconv. Today, I will show you how do i convert string to JSON in golang, as above mentioned I’m going to use the json. An obvious method to escape binary data is to use Base64. Password string `json:"-"`. Unmarshal() method, we have first import "encoding/json" package which is built in provided by golang, then we have to pass our string as a byte array with an assignable Base64 is the most widely used text representation of binary data. 4. Marshal. Float64frombits(bits) return float. ") Feb 6, 2024 · Below are some of the ways by which we can convert a bytes array into JSON format in Python: Using decode and json. When working with data we usually want to encode some Go struct into a json string. The mgo/bson package is used to encode and decode all database commands and results, even when the application does not use the package directly. If you want a string representation of this MongoDB ObjectId, you may use its ObjectID. Otherwise, every JSON object // entry and JSON array value will be on its own line. PublicKey: type PublicKey struct {. Aug 3, 2017 · fmt. org . The script has to make some assumptions, so double-check the output! For an example, try converting JSON from the SmartyStreets API or the GitHub API . Understanding the mapping between JSON and Go structures, and the syntax for unmarshalling JSON data into Go structs and slices, is fundamental for working with JSON May 2, 2019 · What's the fmt code for printing a string as an array of bytes? If I have a marshaled json object, I can print bytes like so: type Fakejs struct { Fake string `json:"fake"` } fjs := Fakejs {Fake:"abc"} mjs, err := json. This results in a representable date range of about 290 million years into the past and future. Bytes() to w. BSON data is slightly larger in byte size. Use two struct types. Unmarshal(objmap["sendMsg"], &s) For say, you can do the same thing and unmarshal into a string: var str string. Reader from a []byte slice, you can use bytes. D. Array: Feb 23, 2014 · // You can use map[string]string as well type User struct { // The `json` struct tag maps between the json name // and actual name of the field Name string `json:"name"` } // This functions accepts a byte array containing a JSON func parseUsers(jsonBuffer []byte) ([]User, error) { // We create an empty array users := []User{} // Unmarshal the Feb 21, 2018 · The json Package. Name string `json:"name"`. They are created at compile time, even when defined as locals in functions, and can only be numbers, characters (runes), strings or booleans. Uint64(bytes) float := math. BSON is a binary serialization format used to store documents and make remote procedure calls in MongoDB. See this question for a detailed explanation. Mar 26, 2020 · This is not a string, it's a distinct type. NewReader(byteData) This will return a value of type bytes. 2. You serialize Golang values using the Marshal () function into a slice of bytes. Then you can unmarshal into a slice of this struct. A. Println(err) return nil, err. A to []byte Mar 27, 2015 · 6. This example uses the Marshal method. shanehanna. 5. One of these is the popular JSON format. The function transforms the JSON string to map, and loads the result at given map address. loads. If your DB model doesn't match your API model, you have two separate models. Please update the second data ["aString"] to be aInterface. err = json. Here's the code for the case where the most significant bit is at index 0 in the array: func ConvertToUint8(mei [8]bool) uint8 {. ) You can use the strconv. I've read how to do this, but only if the JSON array contains keys. X and pubkey. Here's an example of how to use the json. It then works :-) @evanmcdonnal, pretty good chunk of code but a tiny mistake, you append to aString array, which is already allocated to the good size. Simply pass the byte slice as the parameter to the string() function, and it will return the corresponding string representation. The types in this package enable a flexible system for handling this encoding and decoding. A file is already an array of bytes. As part of it, I generated bson array by querying a collection in MongoDB So is there any generic method to translate bson. import (. 1. Examining those errors and fixing them leads to my suggestions above. Int. } You may do the same with pubkey. (I had to deal with the issue since my primary language is Korean. this. There is a way to convert escaped unicode characters in json. Unmarshal(objmap["say"], &str) EDIT: Keep in mind you will also need to export the variables in your sendMsg struct to unmarshal correctly. All you have to do is read it. The composite literal Person{ Name: "Alice" } returns a Person value with the Phone field set to "". This hex encoding is then decoded into a byte slice with a length of 12: Dec 11, 2018 · 4. It does nothing spectacular apart from being fabulous. To convert a string to byte array or slice in Go language use the below one liner code. if t. Price string `json:"JsonPrice"`. And with Marshal, we perform the opposite conversion from a Go object to JSON data. Status int `json:"status"` Result string `json:"result"` Reason string `json:"reason"` } No further explanation needed. So most likely your IntervalData contains an unexported data field, which the json package ignores, only exported fields are marshaled / unmarshaled. Unmarshal([]byte(jsonData), &people): This line unmarshals the JSON array data into the people slice. Unmarshal([]byte(dataJson), &arr) You pass the address of arr to json. Bytes() Function. It might be another service - it doesn't really matter. Hex The output is an array of bytes where each byte represents a character in the original string. Sep 11, 2023 · A Complete Guide to JSON in Golang (With Examples) In this post, we will learn how to work with JSON in Go, in the simplest way possible. bits := binary. You can also encode JSON from a struct, as shown in the following example code. Writer implementation. Quote() and strconv. Even though it would not be Dec 8, 2017 · So I think that you may need to make your struct implement the Marshaler interface by implementing your own MarshalJSON method that makes a more desirable JSON array encoding out of your []uint8. Share. • 4 yr. @keys: Returns an array of keys for an object. As others have pointed out, it's necessary to use a package like this because structs, by their nature, have Feb 4, 2016 · Name string `json:"some_name"`. Reply. Apr 2, 2019 · The : is needed because byte arrays cannot be directly turned to a string while slices can. Take this example: Name string. It's that simple. i need json returned. I need one JSON like this: [{JSON}, {JSON}, ]. Raw. Golang - convert [8]bool to byte. The official BSON specification refers to the BSON Date type as the UTC datetime. Worth noting that type MyArray struct{} and var m []MyArray work, but type MyArray []struct{} and var m MyArray work too. Arrays can be unmarshaled into Go arrays or slices. Cheers! var m []MyArray used to parse that array! Thank you. Jan 29, 2021 · In the original question &arr was passed to json. ObjectID). BSON Date is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970). // This is read from a file, so its avaible as a byte array. Reader) type Domain Understanding the MongoDB BSON ObjectId in Golang. M {} is underlined map[string]interface{} in go-mongo-driver. 58. import ( "fmt" "encoding/json" ) type Book struct { Title string Author string Year int } Mar 28, 2022 · In the main. Unmarshall () function and pass the JSON String as byte array, and address of an empty map as arguments to the function. In this article, we will explore how you can convert a byte array into a string. Let's imagine that now I have {JSON} in each value of array. FirstName string `json:"firstName"`. go file, you’ll add a main function to run your program. The encoding/json package. @fromstr: Converts a string from json. How to encode a struct back to a bytes buffer. var s sendMsg. Any well-known type. By passing an bytes. So: unmarshal into string. LittleEndian. By marshaling the object, you are getting the encoding (bytes) that represents the JSON string. Let's say we have var b [64]byte . Write accepts []byte as a parameter. Feb 27, 2018 · I am trying to unmarshal data which is of type interface. Title} filter["title"] = params. json. Marshal(fjs) fmt. Index ¶ Constants; Variables; func ClockSequence() int; func NodeID() []byte; func NodeInterface() string; func SetClockSequence(seq int) func SetNodeID(id []byte) bool; func SetNodeInterface(name string) bool; func SetRand(r io. For the second example, though, we’re a bit stuck. Most operating systems don't distinguish between text and binary files, but even on those which do, Go is going to read []byte s from both. Note, I can't test this because there's other problems with my browser. May 20, 2016 · So first you have to type assert on the interface{} to []interface{} I can edit my answer to reflect this. This type allows you to look up individual elements without unmarshalling the entire BSON document. It allows you to do encoding of JSON data as defined in the RFC 7159. func Unmarshal(data []byte, v any) error: Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. One possible solution is the "encoding/gob" standard package. Here is a working example of using RawMessage: package May 28, 2018 · If you want to implement your solution by joining the string slice, you need to convert the bytes to their decimal representation using the strconv package: func (ip IPAddr) String() string {. BSON Date type is signed. Raw to []byte or bson. Unmarshal() method. Read(buffer) if err != nil {. Join(s, ". Then, you’ll use the json. you can use this online JSON formatter/validator. Can be used to save some memory when there is a lot of such items live. go. bson. Marshal function. RawMessage into just valid UTF8 characters without unmarshalling it. Bytes are returned, but we can change these to strings in Go. encoding/json unmarshals JSON strings to []bytes by interpreting the JSON string as base64 and you cannot change this (unless you write your own type and implement your own marshaler). Hex() method to get the hex representation of the ObjectId's bytes: mongoId := mongoDoc["_id"] stringObjectID := mongoId. So I need to convert the interface type to []byte and pass it to unmarshal. Mar 24, 2015 · for example, this prints bytes to my terminal- fmt. fileName = name; file = new File(destPath + fileName); Sep 14, 2022 · 2. How to convert ids which is an int array to byte array, as file. If you're migrating from version 1 check out migration. Jun 21, 2016 · In your example code you are referring to r. Code example on how to pretty print JSON in go (golang) func handleRequest( w http. e. X, Y *big. The BSON encoder encodes this value to what is logically the value {"Name": "Alice", "Phone Sep 18, 2009 · The binary data has to be escaped so that it can be placed into a string element (i. There's a great post, here. The codec system is composed of two parts: 1 Jan 8, 2022 · In Go language, strings are nothing but a combination of an array of bytes. result <<= 1. 133k 33 259 274. Feb 26, 2016 · Since you're unmarshaling into an interface{}, the returned types will only be from that set. This avoids the loop and gets us remarkably close: This avoids the loop and gets us remarkably close: package main import "fmt" func main() { bs := []byte{0xff, 0xfd} fmt. JSONDecoder with Custom Decoder. go: main. This package considers both binary BSON and ExtendedJSON as BSON representations. These will give you 2 separate byte slices. With Unmarshal (), we convert data from JSON to a Go struct. decode and io Module. M{"title": params. Space JSON data is slightly smaller in byte size. Wraps a json string. And please read the whole package doc, this is explained in detail. 6. It has 4 fields—a Width, Height, Color and a bool called Open. I managed to use type assertion to get the values from the Points, but using a custom unmarshaller for the array sounds cleaner to me. Only one method call is required. ) type Person struct {. Printf can print slices and arrays and applies the format to the elements of the array. Println("json returned", buffer. You deserialize a slice of bytes into a Golang value using the Unmarshal () function. Aug 22, 2013 · Use the default CommonsMultipartFile where you to use the FileDiskItem object to create it. To start, suppose we have a JSON string, and wish to convert it to a Golang object. Nov 25, 2021 · buffer := make([]byte, filesize) _, err = file. May 25, 2021 · 7. string(b) will fail while string(b[:]) will work. Just sent over. array = "null". Jun 12, 2020 · 31 1 3. Also it expands 3 bytes into 4 characters which leads to an increased data Aug 11, 2022 · Golang JSON to Struct. This tool instantly converts JSON into a Go type definition. protobuf. In this case, it receives an inbound job and sends it to Google PubSub. Oct 17, 2016 · Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand Aug 29, 2016 · I'm trying to create some random int arrays and write it to a xyz. Jan 7, 2020 · 3. Then Marshal function of the json package is used to encode Go values into JSON values. Like JSON, BSON supports the embedding of documents and arrays within other documents and arrays. So if you need to serialize JSON string which you need to deserialize later into struct, do it with json. ObjectID from the interface value. The payload doesn't need to be checked. For example, BSON has a Date type and a BinData type. This function creates a new encoder that writes to an io. Another one is that, in the gc implementation at least, string is a one word smaller entity than []byte. package main. Dec 25, 2022 · In this tutorial, we will explore how to declare a constant array in Golang. The following code converts a BSON document to JSON using the MarshalExtJSON() method, then parses and prints the JSON byte array using string type-casting: Oct 4, 2022 · Golang JSON Unmarshal() Examples Example-1: Parse structured JSON data. Speed JSON is fast to read but slower to build. md for guidance. One difference is that the returned []byte can be potentially reused to hold another/new data (w/o new memory allocation), while string cannot. Title. Similarly, ecdsa. Data Types: The default Golang data types for decoding and encoding JSON are as follows: bool for JSON booleans. Data field! This is inconsistent. NewDecoder can be used to unmarshal JSON data from a byte slice, a file, a network connection, etc. ResponseWriter, req * http. Name string `json:"Name"`. You need some way to safely transport bytes since JSON values can only be string (UTF-8), number, object, array, bool & null. Hot Network Questions Could you actually do orbital deployment? It has RawMessage type, which Marshalls and Unmarshals without escaping. Once you run the above code, you will get an output as shown below. So pass arr. Aug 27, 2018 · A UUID is a 16 byte (128 bit) array. That is the portion that will need to be handled manually. Apr 26, 2017 · 2 Answers. NewEncoder function to convert a Go map to a JSON string: May 8, 2023 · In Go, JSON marshalling is the process of converting a data structure (such as a struct or a slice) into a JSON string using the json. Writer interface. Feb 18, 2023 · Strings, ints—any objects—are supported. Reader (and io. I have stripped the program down to only the part where it handles the JSON data. May 31, 2022 · JSON is a widely used format for data interchange. Sprintf () function to convert byte array to string. Can a string be converted to bytes in Golang? Yes, you can convert a string to bytes in Golang. Mar 6, 2024 · // If empty, the output is compact JSON. The below example is to converts a map type into a JSON string. fmt. Golang provides multiple encoding and decoding APIs to work with JSON including to and from built-in and custom data types using the encoding/json package. There is no []byte in json. err := json. Func notes. My JSON array does not contain keys. } We can see that there is a lot of flexibility in using JSON with Go. // Each line will be preceded by repeated copies of Indent, where the // number of copies is the current indentation depth. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding. Unmarshalling is the reverse process Golang program to demonstrates how to encode map data into a JSON string. No automatic type conversions, by default everything is a []byte, but it provides you value type, so you can convert by yourself (there is few helpers included). There are a bunch of ways to do it. Jun 24, 2014 · How to convert type to byte array golang. Jan 20, 2019 · Ultimately I did not use a bson. BSON is slow to read but faster to build and scan. I've tried Unmarshal in xml package with no success: Oct 24, 2018 · By default byte slices are marshalled as Base64 strings and byte arrays are converted as is: func main() { type Foo struct { ByteSlice []byte ByteArray [6]byte } foo : Apr 23, 2019 · 485. txt file in Golang. Unmarshal() to unmarshal a JSON array, but arr is not an array (or slice), it is a struct value. The MongoDB BSON object _id in Golang is a hexadecimal (base 16) encoding of a MongoDB timestamp string. Request) { body := App. Situation: Trying to build a filter and one of the bson. Unmarshal(): unmarshaled := json. BSON, short for Binary JSON, is a binary-encoded serialization of JSON-like documents. First we have a type Box, which is a custom struct. It then publishes the payload to one or more services that expect a byte array. A when I was trying to pass an array. Simple example. "fmt". convert int array to byte array in Dec 19, 2019 · In the first example, the normal approach to using this in Go would be quite straight forward: type Result struct {. It's pretty much just a helpful wrapper for navigating hierarchies of map[string]interface{} objects provided by the encoding/json package. You can only type assert primitive. Output destination: json. Convert JSON String to Map. Apr 12, 2024 · Package bson is a library for reading, writing, and manipulating BSON. The gob package creates an encoder/decoder that can encode any struct into an array of bytes and then decode that array back into a struct. input := []byte("1. You can use the Raw type to retrieve elements from a BSON document byte slice without unmarshalling it to a Go type. @flatten: Flattens an array. Add the following lines to main. [ 2] Oct 9, 2016 · I have a very simple Go webserver. You either need to convert from the map[string]interface{} that the json object is being unmarshaled into, or unmarshal directly into the struct type you want. Jul 11, 2014 · 15. BSON: Type JSON files are written in text format. ReadSeeker) interface. Jun 15, 2012 · 11. It's because []byte != string if you've come from C or similar and have been using byte as a char replacement. Unwraps a json string. These values are decoded properly when unmarshalled. Sep 12, 2022 · There is not an option to change the JSON decoder's expectation that the value for a []byte is base64 encoded. The closest equivalent of C's sizeof would return the entire array's allocated size, not the portion you were using. Aug 1, 2013 · Golang - zero value byte array. Description string `json:"description"`. } To parse your other JSON text, create a Go struct that models the JSON data. ago. It helps write application easily that interacts with an API. package main Operates with JSON payload on byte level, providing you pointers to the original data structure: no memory allocation. @group: Groups arrays of objects. Sep 3, 2017 · The following snippet is from another post : here but obviously it doesn't work for the scenario described above. Another way to convert a string to a byte array is by using the strings. The runtime thinks []byte is binary data and tries to encode it in base64 string. To avoid unnecessary conversion from String to byte[] which enforces encoding based on the provided charset, I prefer to use JsonWriter directly with ByteArrayOutputStream for instance ( JsonValue subtypes use JsonWriter with StringWriter ): ByteArrayOutputStream stream = new ByteArrayOutputStream(); Json. The BSON specification is located at https://bsonspec. NewReader in the bytes package: r := bytes. The following struct should be convertable from that json: type resp struct { Items []struct { Project string `json:"project"` Article string `json:"article"` Granularity string `json:"granularity"` Timestamp string `json:"timestamp"` Access string `json:"access Jul 13, 2021 · 2. UUIDs may be used as keys to maps or compared directly. Category string `json:"category"`. Unmarshal can only be used to unmarshal JSON data from a byte slice. If you want the string, you have to convert those bytes to a string. []byte(string) We can use byte array to store a collection of binary data, for example, the contents of a file. The documentation states: type RawMessage []byte. Apr 7, 2016 · Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string, and a nil slice encodes as the null JSON object. Itoa(int(i))) } return strings. Nov 17, 2021 · Go encodes map data structures to JSON key-value objects. Example: Approach 2: Create your own custom multipart file object and convert the byte array to multipartfile. var array string. With Marshal and Unmarshal, we convert to JSON data and from JSON data. Golang provides a built-in encoding library. @values: Returns an array of values for an object. I thought I needed to use bson. Ask Question Asked 10 years, 9 months ago. Golang - conversion between structs. Iterate through the bits, shifting and setting as you go. Convert byte array to string using bytes package. type User struct {. Thanks in advance for your suggestions. loads() Using bytes. Golang Json Marshal Example. The reason why this is done is that JSON does not have a native representation for raw bytes. Thanks a lot, i will play with this. Let’s see them in the below section with examples. Title != "" {. RawMessage with interface{}: type ServerResponse struct {. The above code to convert string to byte slice is very useful while using ioutil. elliptic. RawMessage: package main. Bytes() returns you the bytes of the D big integer. ← Previous Post. Marshal function to marshal the map data into JSON data. Apr 11, 2012 · 3. We will learn how to convert from JSON raw data (strings or bytes) into Go types like structs, arrays, and slices, as well as unstructured data like maps and empty interfaces. Does not parse full record, only keys you specified Jan 13, 2023 · Another way to convert golang map to JSON is using json. Unquote() to do the conversion. Body["array"] = json. M{} if params. Nov 29, 2018 · In the future, you could consult JSON-to-Go if you're unsure how to convert a JSON object to a struct -- it's quite useful. Convert A Bytes Array Into Json Format Using decode and json. data which is an unexported field! But your type IntervalData has an exported IntervalData. Y fields. Using nodejs was easier because I could send all records in one JSON document. Paste a JSON structure on the left and the equivalent Go type will be generated to the right, which you can paste into your program. Encoder() function. Output: String = HELLO. zero or more Unicode chars in double quotes using backslash escapes) in JSON. What is the correct way to achieve writing random integer arrays to a text file. float64 for JSON numbers. Sorted by: 20. To view a readable form of the JSON encoding, you must use an unmarshaler method or string type-casting to parse the JSON byte format. Write, won't it return a stream of bytes as well. loads() Using str() with decode and json. Indent method to print JSON in go (golang) Use json. Jan 12, 2023 · Use the json. "encoding/json". Nov 27, 2012 · What is an optimal solution to encode and decode a string array ([]string) to a byte array ([]byte)? I was thinking of iterating the string array twice, first one to get the actual size needed for the byte array and then a second one to write the length and actual string ([]byte(str)) for each element. Bytes() function from the standard library. The Go standard library offers a package that has all you need to perform JSON encoding and decoding. I tried. To use the json. I chose my words carefully, and the question was about a slice ([]byte), where the capacity is the size of the underlying array; the array pointed to by the field array in the slice struct. First we need to add the package encoding/json to the list of imports. I think what you are looking for is the RawMessage type in the encoding/json package. s := make([]string, 0, len(ip)) for _, i := range ip {. To get a type that implements io. Method 2: Convert a String to a Byte Array Using the strings. } else {. Oct 15, 2014 · golang casting byte array to struct. Println(string(urlsJson)) answered Jul 11, 2014 at 3:27. 11") Sep 25, 2018 · So privkey. Buffer as the io. It does not matter if the map contains strings, arrays, structures, numerical values, or another map. RawMessage is a raw encoded JSON object. Curve. Jan 30, 2023 · This means that json. Next, you’ll add a map[string]interface{} value with various keys and types of data. Bytes()), if I pass buffer. Go supports several serialization formats in the encoding package of its standard library. Just assign that value to map's key as below. You can convert a string into a bytes array, similarly, you can convert a byte array into a string. The array will unmarshal into a [][]interface{} of points. We can use the bytes package NewBuffer () function to create a new Buffer and then use the String () method to get the string output. The only thing you should remember is that JSON allows only string keys, so if you have an integer key in your map, it will be converted to a string. D elements is an array. Printf("%08b\n", bs) // prints [11111111 11111101] } Apr 6, 2018 · This is the code for retrieving the above data The struct is: Id int `json:"id"`. We’ll be focusing on the BSON ObjectID throughout this tutorial, so let’s begin by taking a look at its format. Println(mjs) Produces [123 34 102 97 107 101 34 58 34 97 98 99 34 125] Which is what I want. //filter = bson. Unmarshal([]byte(kpi), &a) => failed Mar 27, 2017 · serverResponse. Using fmt. MustReadBody( req, w) // get the respone body if body == nil { return } var prettyJSON bytes. Indent method. Reader which implements the io. I suggest to format the JSON to see the real structure, e. May 31, 2022 · The most straightforward but pretty inefficient method to convert a struct into a byte slice is to marshal it to JSON/YAML or any other markup language format. First we have to understand what is constant and array golang: constants: Constants in Go are just that—constant. Encode and Decode We can send JSON through APIs without encoding and I am writing code in GoLang. Gabs is a small utility for dealing with dynamic or unknown JSON structures in Go. – Sep 17, 2014 · Is there a way to convert XML ([]byte) to JSON output in Golang? I've got below function where body is []byte but I want to transform this XML response to JSON after some manipulation. Unmarshal requires a pointer to a Golang data structure as an argument to store the decoded JSON data. Struct declarations can be nested inside one another. Apr 25, 2014 · I am trying to decode a JSON array and put it in a slice of a struct. It compiles and can be found below. Array == nil {. However, Base64 has a high processing overhead. Jeff Mercado. An alternative approach is to replace the use of json. The question: how to convert []bson. Again, handle the err to check for errors during unmarshalling. @join: Joins multiple objects into a single object. filter := bson. It's job is to receive an inbound json payload. – Volker. RawMessage(`["a", "b", "c"]`) The program in the question compiles and runs with errors. Buffer. write(obj); Jun 30, 2023 · To convert bytes to a string in Golang, you can use the string() function. May 2, 2013 · 52. The json package doesn't know about Something1 and Something2. (primitive. BSON also contains extensions that allow representation of data types that are not part of the JSON spec. Aug 1, 2021 · In Go, you can easily convert a map to a JSON string using encoding/json package. To convert JSON String to Map object in Go language, import the package encode/json, call json. Modified 10 years, Since a byte array can be cast into other data types, I can't figure Jul 31, 2015 · @evanmcdonnal: no I'm not. Array []uint8. . @tostr: Converts json to a string. Indent string // AnyResolver is used to resolve the google. BSON files are written in binary. wi iq wo tb ky el em mb xe if