Reputation: 658
i am trying to place a JSON entry in yaml . but its not compiling . My expected yaml file is like below .
http:
port: "8081"
ABC:
CustomFieldJson: "[
{
"FieldName": "uw_firm",
"FieldValue" :"NULL"
},
{
"FieldName": "uw_type",
"FieldValue" :"Delegated"
}
]"
How i can fix this?
Upvotes: 0
Views: 5191
Reputation: 4336
The easiest way in this case is to use a "literal block scalar". This way you don't have to escape anything.
The literal block scalar is introduced with a |
pipe sign.
http:
port: "8081"
ABC:
CustomFieldJson: |
[
{
"FieldName": "uw_firm",
"FieldValue" :"NULL"
},
{
"FieldName": "uw_type",
"FieldValue" :"Delegated"
}
]
(More about quoting in YAML)
Upvotes: 1
Reputation: 3913
The solution is to escape the double quotes in the json value. Escape sequences are acceptable in YAML when using double quotes for the scalar value. And this scalar value could be json as in your case.
An example will make it clear:
http:
port: "8081"
ABC:
CustomFieldJson: "[
{
\"FieldName\": \"uw_firm\",
\"FieldValue\" :\"NULL\"
}
]"
This page has useful information.
Upvotes: 1