| 303 | } |
| 304 | |
| 305 | func (j *JSONPath) findFieldInValue(value *reflect.Value, node *FieldNode) (reflect.Value, error) { |
| 306 | t := value.Type() |
| 307 | var inlineValue *reflect.Value |
| 308 | for ix := 0; ix < t.NumField(); ix++ { |
| 309 | f := t.Field(ix) |
| 310 | jsonTag := f.Tag.Get("json") |
| 311 | parts := strings.Split(jsonTag, ",") |
| 312 | if len(parts) == 0 { |
| 313 | continue |
| 314 | } |
| 315 | if parts[0] == node.Value { |
| 316 | return value.Field(ix), nil |
| 317 | } |
| 318 | if len(parts[0]) == 0 { |
| 319 | val := value.Field(ix) |
| 320 | inlineValue = &val |
| 321 | } |
| 322 | } |
| 323 | if inlineValue != nil { |
| 324 | if inlineValue.Kind() == reflect.Struct { |
| 325 | // handle 'inline' |
| 326 | match, err := j.findFieldInValue(inlineValue, node) |
| 327 | if err != nil { |
| 328 | return reflect.Value{}, err |
| 329 | } |
| 330 | if match.IsValid() { |
| 331 | return match, nil |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | return value.FieldByName(node.Value), nil |
| 336 | } |
| 337 | |
| 338 | // evalField evaluates field of struct or key of map. |
| 339 | func (j *JSONPath) evalField(input []reflect.Value, node *FieldNode) ([]reflect.Value, error) { |