What is a proper AWSJSON?

Viewed 1811

I have used this

var jsonData = {"hello": 20};

while passing this to graphql query

products:jsonData

it fails with this error

Validation error of type WrongType: argument 'input.products' with value 'StringValue{value='{hello: 20}'}' is not a valid 'AWSJ

ps help

3 Answers

AWSJSON is a JSON string.

EDIT: Appsync accepts *escaped* JSON strings "{\"hello\":20}" as valid AWSJSON.

var jsonData = "{\"hello\":20}"
final jsonEncoder = JsonEncoder();
const JsonEncoder encoder = JsonEncoder.withIndent('  ');
String sta = jsonEncode(encoder.convert(_products));

then pass

products: $sta

This worked for me

This will work

var jsonData="{\n \"hello\":20}"

Related