Skip to content

parsing error for arrays of objects #110

@blgm

Description

@blgm
package main

import (
	"fmt"

	"code.cloudfoundry.org/jsonry"
)

func main() {
	data := `{"nfs":[{"volume_mounts":[{"container_dir":"foo"}]}]}`

	var receiver struct {
		Paths []string `jsonry:"nfs.volume_mounts.container_dir"`
	}

	if err := jsonry.Unmarshal([]byte(data), &receiver); err != nil {
		panic(err)
	}

	fmt.Printf("%+v", receiver.Paths)
}

You'd expect this to extract the string foo, but it panics with:

panic: cannot unmarshal "[foo]" type "[]interface {}" into index 0 (type "string") path Paths[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions