Search code examples
javascriptjsonamazon-web-servicesmodelaws-api-gateway

AWS Model - JSON string inside string type


What I'm trying to do is to have a basic model that takes in a JSON string rather than defined all my variables/elements upfront. My model will take in an "options" element which I want to contain a json string. My model is below.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "GroceryStoreInputModel",
  "type": "object",
  "properties": {
    "options":{"type":"string"}
  }
}

in my api-gateway, this will work with i just do a basic body like this:

{"options":"this is my options"}

but i get a model not matching error if I replaced the string with a json string.

  {"options":"{\\"name\\":\\"thaison\\",\\"mail\\":\\"test2\\"}"}

I also tried "" escaped but did not work as well, is there a way to do this?

{"options":"{""name"":""thaison"",""mail"":""test2""}"}

Solution

  • it looks like your payload value for the options node is being interpreted as object instead of string. Can you try the following settings instead to solve the problem?

    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "title": "GroceryStoreInputModel",
      "type": "object",
      "properties": {
        "options":{"type":"object"}
      }
    }