5

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 Answers3

2

AWSJSON is a JSON string.

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

var jsonData = "{\"hello\":20}"
fedonev
  • 20,327
  • 2
  • 25
  • 34
  • Thanks . Still Validation error of type WrongType: argument 'input.products' with value 'StringValue{value='{'hello':20}'}' is not a valid 'AWSJSON' –  Nov 12 '21 at 15:55
  • Does the error occur if you execute the query directly in the appsync console or postman? Or is the error specific only to whatever app client you are using? – fedonev Nov 12 '21 at 16:15
  • I am doing it in the appsync and the within the client. See the answer I posted that worked for me –  Nov 12 '21 at 16:23
0
final jsonEncoder = JsonEncoder();
const JsonEncoder encoder = JsonEncoder.withIndent('  ');
String sta = jsonEncode(encoder.convert(_products));

then pass

products: $sta

This worked for me

0

This will work

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

prachi
  • 113
  • 1
  • 8