Extracting data from an incomplete JSON array
This recipe contains a very specific use case, where your program consumes the JSON from an unreliable source and the JSON contains an array of objects which has the beginning token [ but the number of items in the array is very large, and the end of the JSON could be corrupted.
How to do it...
- Open the console and create the folder
chapter05/recipe13. - Navigate to the directory.
- Create the
json.gofile with the following content:
package main
import (
"encoding/json"
"fmt"
"strings"
)
const js = `
[
{
"name":"Axel",
"lastname":"Fooley"
},
{
"name":"Tim",
"lastname":"Burton"
},
{
"name":"Tim",
"lastname":"Burton"
`
type User struct {
Name string `json:"name"`
LastName string `json:"lastname"`
...