Skip to content

Array() and StringArray() do not work. #79

@brendesp

Description

@brendesp

I don't think the following test is correct.

func (j *Json) Array() ([]interface{}, error) {
  if a, ok := (j.data).([]interface{}); ok {
    return a, nil

j.data is already an interface{} so it will never be an []interface{}.

I think the correct test is:

func (j *Json) Array() ([]interface{}, error) {
  if reflect.TypeOf(j.data).Kind() == reflect.Array {
    v := reflect.ValueOf(j.data)
    a := make([]interface{}, v.Len())
    for i := 0; i < v.Len(); i++ {
      a[i] = v.Index(i)
    }
  return a, nil

I will test this locally.

Please let me know if I misunderstand what you are doing here.

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