Using JQ I would like to take a complex JSON object that includes JSON embedded as strings and then turn it all into a valid string I can easily embed in other JSON objects.
For example, lets say I have this json object:
{
"region": "CA",
"waf_rule_tags": "{\"RULEID:942100\":[\"application-multi\",\"language-multi\",\"platform-multi\",\"attack-sqli\",\"OWASP_CRS/WEB_ATTACK/SQL_INJECTION\",\"WASCTC/WASC-19\",\"OWASP_TOP_10/A1\",\"OWASP_AppSensor/CIE1\",\"PCI/6.5.2\"]}"
}
I need to turn this all into the following string:
"{\"region\": \"CA\",\"waf_rule_tags\": \"{\\\"RULEID:942100\\\":[\\\"application-multi\\\",\\\"language-multi\\\",\\\"platform-multi\\\",\\\"attack-sqli\\\",\\\"OWASP_CRS/WEB_ATTACK/SQL_INJECTION\\\",\\\"WASCTC/WASC-19\\\",\\\"OWASP_TOP_10/A1\\\",\\\"OWASP_AppSensor/CIE1\\\",\\\"PCI/6.5.2\\\"]}\"}"
That way I can take this string and insert it exactly under the text
field of another JSON object to create the following.
{
"title": "12345-accesslogs",
"text": "{\"region\": \"CA\",\"waf_rule_tags\": \"{\\\"RULEID:942100\\\":[\\\"application-multi\\\",\\\"language-multi\\\",\\\"platform-multi\\\",\\\"attack-sqli\\\",\\\"OWASP_CRS/WEB_ATTACK/SQL_INJECTION\\\",\\\"WASCTC/WASC-19\\\",\\\"OWASP_TOP_10/A1\\\",\\\"OWASP_AppSensor/CIE1\\\",\\\"PCI/6.5.2\\\"]}\"}",
"priority": "normal",
"tags": ["environment:test"],
"alert_type": "info"
}