I have the following json which needs to convert to YAML
{
"siteidparam": "lid",
"sites": [
{
"name": "default",
"routingmethod": {
"method": "urlparam",
"siteid": "default",
"urlpath": "default"
}
},
{
"name": "csqcentral",
"routingmethod": {
"method": "urlparam",
"siteid": "capitolsquare",
"urlpath": "csq"
}
}
]
}
I used online JSON to YAML converter and it gave the following output,
---
siteidparam: "lid"
sites:
-
name: "default"
routingmethod:
method: "urlparam"
siteid: "default"
urlpath: "default"
-
name: "csqcentral"
routingmethod:
method: "urlparam"
siteid: "capitolsquare"
urlpath: "csq"
when I tried to convert the same generated YAML back to json from the online service, it gives "Unable to parse" exception.
1.) what is the correct way of representing above kind of jsons in YAML?
I want to read this kind of YAML inside my golang program. For that I'm using spf13/viper library, but I couldn't find any method which is able to decode this king of array objects.
2.) How to read this kind of YAML in golang using viper? Sample code would help.