What is the process for creating a JSON message to be sent using Amazon SES?

Whenever I attempt to send an email using Amazon-SES, I keep encountering the following error:

Error encountered while parsing parameter '--raw-message': JSON is invalid. A property name enclosed in double quotes is expected: line 1 column 2 (char 1)

I'm puzzled as to where I might be going wrong with the JSON message...

Below is the bash script I've been utilizing:

echo '{\"Data\": 
"Subject:'${SUBJECT}'\\n
MIME-Version: 1.0\n
Content-type: Multipart/Mixed; 
boundary=\"NextPart\"\\n\\n--NextPart\\n
Content-Type: text/plain\\n\\n'${BODY}'
\\n\\n--NextPart
\\nContent-Type:'${ATTACHMENT_TYPE}';
\nContent-Disposition: attachment; 
filename=\"'${ATTACHMENT_FILE_NAME}'\"\\n
\\n'$(cat ./${ATTACHMENT_FILE_TO_READ_FROM_DISK})'
\\n--NextPart--"}' > "$tmp_message"

aws ses send-raw-email --region us-east-1 --from <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a495f545e5f487a5d575b535614595557">[email protected]</a> --destination file://$tmp_destination --raw-message file://"$tmp_message"

Answer №1

Check your JSON data using jq

#! /bin/bash

echo '{\"Data\": 
"Subject:'${SUBJECT}'\\n
MIME-Version: 1.0\n
Content-type: Multipart/Mixed; 
boundary=\"NextPart\"\\n\\n--NextPart\\n
Content-Type: text/plain\\n\\n'${BODY}'
\\n\\n--NextPart
\\nContent-Type:'${ATTACHMENT_TYPE}';
\nContent-Disposition: attachment; 
filename=\"'${ATTACHMENT_FILE_NAME}'\"\\n
\\n'$(cat ./${ATTACHMENT_FILE_TO_READ_FROM_DISK})'
\\n--NextPart--"}' > "$tmp_message"

if jq < "$tmp_message"; then
    aws ses send-raw-email --region us-east-1 --from <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83f0e6ede7e6f1c3e4eee2eaefade0ecee">[email protected]</a> --destination file://"$tmp_destination" --raw-message file://"$tmp_message"
else
    echo "ERROR" >&2
fi


Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to retrieve JSON data in Angular.js

I'm having trouble accessing a json file in angular.js with the code below. I keep getting an error message and could really use some help! Here is my module : angular.module("demoApp", ['demoApp.factory','demoApp.controllers']); ...

Guide to extracting a key from a specific index within JSON using Google Apps Script

Is there a way to extract values key11-key44? Just managed to retrieve values key1-key4: const data = JSON.parse(UrlFetchApp.fetch(url, options); const keys = Object.keys(data.paths); for (let a in keys) {return keys[a]} { "id": &q ...

Converting a JSON object to a string in Java

I am working with a JSON file and looking to convert it from JSON to string using the org.simple.json library. { "header": { "IssuerID": "000141", "AuthenticationID": "e07020c0d040a050a0808099", "AuthenticationDateTime ...

iterating over a large multidimensional array in JavaScript

I am facing a challenge with handling a large JSON dataset (around 20k+ entries, totaling over 2mb) that I need to display on my web pages. Currently, I fetch this data using AJAX and parse it using JSON.parse in JavaScript, resulting in a complex multidi ...

Struggling to update state data with response data in React, despite the response not being empty

I'm currently working on my first React API application and I am facing an issue where the state data appears to be empty even after assigning res.data, which is not empty. Additionally, I am struggling with rendering all of this content inside a div. ...

Steps for converting a file with JSON objects to a JSON array

I have a JSON file with multiple objects stored in a single file that I need to convert into a JSON array using JavaScript. My main objective is to create a CSV file from this data. Here is an example of the file content: { Name:"nom1", Cities:[&apos ...

Unexpected value detected in D3 for translate function, refusing to accept variable

I'm experiencing a peculiar issue with D3 where it refuses to accept my JSON data when referenced by a variable, but oddly enough, if I print the data to the console and manually paste it back into the same variable, it works perfectly fine. The foll ...

Using Custom GeoJSON Data with HighMaps Tutorial

Currently, I have created a custom .geo.json file from a county shapefile using ogr2ogr. My goal is to manually add values for each county. After studying a jsfiddle example (link provided), I'm unsure how to merge the two together. The specific line ...

Reading a file and inserting its content into a database is causing Unicode strings to be

Currently, I am facing an issue while reading a JSON string from a file, parsing it, and then inserting the data into a MySQL database. The insert query is generating the following error message: SQLSTATE[HY000]: General error: 1366 Incorrect string valu ...

Effortless form submission through Angular

When attempting to create a form submit using Angular $http, the following codes were utilized. HTML (within the controller div): <input type="text" name="job" ng-model="item.job"> <button type="submit" ng-click="post()">Add</button> J ...

Utilize AngularJS to enable the forward and back buttons to fetch JSON data, but ensure that the data is only retrieved if the item meets

I have successfully implemented forward and back buttons for paging through data items in an array from a JSON file: Controller: dishControllers.controller('DrinkcardsController', ['$scope','$http','$routeParams', ...

How can I distinguish between a decimal and a long numeric token when using a custom JsonConverter with Utf8JsonReader?

I am working with a json converter that needs to convert a given property value to either a decimal or a long, depending on the type of value. However, I am facing an issue where I cannot determine if the property value is a decimal or a long since the t ...

Combining a JSON file and a CSV file into a pandas dataframe for analysis

I have a JSON file with geographic data that includes information on population counts for different areas represented by WK_CODE. { "type" : "FeatureCollection", "name" : "NBG_DATA.CBSWBI", "feature ...

Extracting JSON data from a column in Presto

In my Presto table, there is a specific structure that I am trying to achieve. Specific Date Specific Rates 1/1/2022 {"USD":"725.275","GBP":"29.275000000000002","CAD":"0.713352"} 1/2/202 ...

Exploring the Connection with JSON-server

While creating a simulated API using json-server, I encountered an issue with passing a query. When utilizing _expand, I am able to display the parameters of a relationship, but it doesn't seem to work when the relationship is nested within a child. ...

I received incorrect JSON data

Take a look at my PHP code for encoding JSON data from MySQL database. Check out the URL . I validated the JSON data using JSONLint, which showed it as valid. However, instead of receiving the data in JSON format, I got the result [false]. Can anyone hel ...

A step-by-step guide on converting a JSON object to a CSV file using the json2csv nodejs module

I'm in the process of learning how to convert a JSON object into a CSV file using the json2csv node module. This is completely new to me as I have not worked with JSON previously. The structure of my JSON object is as follows: { "car": { ...

Issues Persist with Updating mySQL Database using PHP

I've been attempting to insert location data into a MySQL database using my PHP server from the TripTracker Android App. However, despite trying different approaches in PHP, I have not been successful so far. Any assistance would be much appreciated. ...

Avro Schema: ensure the interpretation of value (map, array) as a string

I need to convert JSON data to Avro format using NiFi, but the JSON has nested complex types that I want to be represented as simple strings. Here is an example of JSON data: "FLAGS" : {"FLAG" : ["STORED","ACTIVE"]} How can I instruct AVRO to store the ...

guide for interpreting a complex json structure

I'm attempting to extract data from a JSON file that has multiple layers, like the example below. - "petOwner": { "name":"John", "age":31, "pets":[ { "animal":"dog", "name":"Fido" }, ...