package lzUtils

import "github.com/bytedance/sonic"

func RecursiveParse(data interface{}) (interface{}, error) {
	switch v := data.(type) {
	case string:
		// 尝试解析字符串是否为嵌套 JSON
		var parsed interface{}
		if err := sonic.Unmarshal([]byte(v), &parsed); err == nil {
			return RecursiveParse(parsed)
		}
		return v, nil // 普通字符串直接返回
	case map[string]interface{}:
		for key, val := range v {
			parsed, err := RecursiveParse(val)
			if err != nil {
				return nil, err
			}
			v[key] = parsed
		}
		return v, nil
	case []interface{}:
		for i, item := range v {
			parsed, err := RecursiveParse(item)
			if err != nil {
				return nil, err
			}
			v[i] = parsed
		}
		return v, nil
	default:
		return v, nil
	}
}
