Setting and extracting the SNS message payload

Published: Friday, May 5, 2017 Last modified: Monday, Jan 24, 2022

Consider eg.json:

{
  "Records": [
	{
	  "Sns": {
		"Message": ""
	  }
	}
  ]
}

Embed a JSON string in to the Message

jq --argfile file eg.json '.Records[0].Sns.Message = ($file | tojson)' eg.json

Extract a JSON stringified into the Message

jq --argfile file eg.json '.Records[0].Sns.Message = ($file | tojson)' eg.json |
jq '.Records[0].Sns.Message|fromjson'