如何在YAML文件中将JSON数据集作为字符串传递?

how can i have a key in YAML format which accepts a json data as a string? I tried to put the json data in quotes but it reads as a list of map.

test1: '[{'a':'abd','asxs': 'csd','sx':'sft'}]'
test2: default

I want yaml to read 'test1' as string rather than a list of dicts/maps. how do i get it?

I get below error:

Failed while parsing request input: field "Request" field "string" can only parse list of bytes or characters, invalid element: map["a":"abd" "asxs":"csd" "sx":"sft"]

Define test1 as a string instead of []map[string]string. you can use go-yaml for parsing and loading your data into your struct's fields. hope I understood your question correctly, if not please leave a comment. here's a complete example (make sure to define your vars with capital letter in the beginning e.g. Test1)

package main

import (
    "log"
    "gopkg.in/yaml.v2"
)

func main() {
    var data = `
   test1: "[{ 'a': 'abd', 'ases': 'cad', 'sx': 'sft' }]"
   test2: default
   `

    type T struct {
        Test1 string
        Test2 string
    }
    t := T{}
    err := yaml.Unmarshal([]byte(data), &t)
    if err != nil {
        log.Fatalf("error: %v", err)
    }

    println("test1 value: ", t.Test1)
}