Home > Net >  Parse Error: Unexpected token o in JSON at position
Parse Error: Unexpected token o in JSON at position

Time:05-22

I have this data saved in my table

{
 "uid": {
  "S": "poi_ac13603c-4668-42b0-b889-b7b4bf340f67"
 },
 "address": {
  "M": {
   "block": {
    "S": ""
   },
   "buildingName": {
    "S": ""
   },
   "floorNumber": {
    "S": ""
   },
   "postalCode": {
    "S": "247692"
   },
   "streetName": {
    "S": "26A Dempsey Rd"
   },
   "unitNumber": {
    "S": ""
   }
  }
 },
 "archived": {
  "BOOL": false
 },
 "body": {
  "S": ""
 },
 "businessHour": {
  "L": []
 },
 "categories": {
  "L": []
 },
 "categoryDescription": {
  "S": "Food & Beverages"
 },
 "childFriendly": {
  "S": "N"
 },
 "companyDisplayName": {
  "S": ""
 },
 "companyName": {
  "S": ""
 },
 "contact": {
  "M": {
   "otherContactNo": {
    "S": ""
   },
   "primaryContactNo": {
    "S": ""
   },
   "secondaryContactNo": {
    "S": ""
   }
  }
 },
 "createdAt": {
  "N": "1"
 },
 "customPoi": {
  "S": ""
 },
 "dataset": {
  "S": "food_beverages"
 },
 "description": {
  "S": "Tanglin Gin Distillery"
 },
 "endingPoint": {
  "S": ""
 },
 "images": {
  "L": [
   {
    "M": {
     "url": {
      "S": "https://vs-XXX-prod.s3.ap-southeast-1.amazonaws.com/abc56b53-cc2a-4831-bdf2-9ccec12571e1-1201-0530_tanglin-gin-8-medium-imresizer.jpg"
     }
    }
   }
  ]
 },
 "isPrivate": {
  "S": "FALSE"
 },
 "location": {
  "M": {
   "latitude": {
    "N": "1.3055196856574762"
   },
   "longitude": {
    "N": "103.81188168999205"
   }
  }
 },
 "metadata": {
  "M": {}
 },
 "name": {
  "S": "Tanglin Gin Distillery"
 },
 "nearestMrtStation": {
  "S": ""
 },
 "noOfRooms": {
  "S": "0"
 },
 "officialWebsite": {
  "S": "https://tanglin-gin.com"
 },
 "poiType": {
  "S": ""
 },
 "pricing": {
  "M": {
   "adult": {
    "S": ""
   },
   "child": {
    "S": ""
   },
   "others": {
    "S": ""
   },
   "seniorCitizen": {
    "S": ""
   }
  }
 },
 "rating": {
  "N": "0"
 },
 "reviews": {
  "L": []
 },
 "source": {
  "S": "STB"
 },
 "startingPoint": {
  "S": ""
 },
 "thumbnails": {
  "L": []
 },
 "tourDuration": {
  "S": ""
 },
 "updatedAt": {
  "N": "1"
 },
 "wheelChairFriendly": {
  "S": "N"
 }
}

and my schema is this

var schemaDefinition = {
  uid: {
    type: String,
    hashKey: true
  },
  tihUuid: {
    type: String,
    default: ""
  },
  name: {
    type: String,
    required: true
  },
  categoryDescription: {
    type: String,
    default: ""
  },
  archived: {
    type: Boolean,
    default: false
  },
  images: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  thumbnails: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  body: {
    type: String,
    default: ""
  },
  initialDescription: {
    type: String,
    default: ""
  },
  description: {
    type: String,
    default: "",
  },
  shortDescription: {
    type: String,
    default: ""
  },
  poiType: {
    type: String,
    default: ""
  },
  source: {
    type: String,
    default: ""
  },
  dataset: {
    type: String,
    default: ""
  },
  address: {
    type: Object,
    default: {}
  },
  nearestMrtStation: {
    type: String,
    default: ""
  },
  amenities: {
    type: String,
    default: ""
  },
  startDate: {
    type: Date,
    default: ""
  },
  endDate: {
    type: Date,
    default: ""
  },
  companyDisplayName: {
    type: String,
    default: ""
  },
  companyName: {
    type: String,
    default: ""
  },
  contact: {
    type: Object,
    default: {}
  },
  defaultLanguage: {
    type: String,
    default: ""
  },
  eventOrganizer: {
    type: String,
    default: ""
  },
  frequencyOfTours: {
    type: String,
    default: ""
  },
  location: {
    type: Object,
    default: {}
  },
  officialEmail: {
    type: String,
    default: ""
  },
  officialWebsite: {
    type: String,
    default: ""
  },
  price: {
    type: String,
    default: ""
  },
  pricing: {
    type: Object,
    default: {}
  },
  rating: {
    type: Number,
    default: 0.0
  },
  startingPoint: {
    type: String,
    default: ""
  },
  endingPoint: {
    type: String,
    default: ""
  },
  stories: {
    type: String,
    default: ""
  },
  supportedLanguage: {
    type: String,
    default: ""
  },
  tags: {
    type: String,
    default: ""
  },
  tourDuration: {
    type: String,
    default: ""
  },
  typeDescription: {
    type: String,
    default: ""
  },
  minimumAge: {
    type: String,
    default: ""
  },
  notes: {
    type: String,
    default: ""
  },
  origin: {
    type: String,
    default: ""
  },
  reviews: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  businessHour: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  metadata: {
    type: Object,
    default: {}
  },
  temporarilyClosed: {
    type: String,
    default: ""
  },
  createdAt: {
    type: Date,
    default: ""
  },
  updatedAt: {
    type: Date,
    default: ""
  },
  district: {
    type: String,
    default: ""
  },
  categories: {
    type: Array,
    default: []
  },
  advanceBookingRequired: {
    type: Boolean,
    default: false
  },
  priceRange: {
    type: String,
    default: ""
  },
  area: {
    type: String,
    default: ""
  },
  wetWeatherFriendly: {
    type: Boolean,
    default: false
  },
  reasonsToGo: {
    type: Array,
    schema: [String],
    default: []
  },
  staffTips: {
    type: String,
    default: ""
  },
  goodFor: {
    type: Array,
    schema: [String],
    default: []
  },
  accessibility: {
    type: Array,
    schema: [String],
    default: []
  },
  facilities: {
    type: Array,
    schema: [String],
    default: []
  },
  dietaryRestrictions: {
    type: Array,
    schema: [String],
    default: []
  },
  awardWinning: {
    type: Array,
    schema: [String],
    default: []
  },
  cuisine: {
    type: String,
    default: ""
  },
  typeOfCuisine: {
    type: Array,
    schema: [String],
    default: []
  },
  toursAndExperiences: {
    type: Array,
    schema: [String],
    default: []
  },
  descriptiveLabels: {
    type: Object,
    default: {}
  }
}

But when I do scan

var response = await klass.scan().exec()

I'm getting this error

{
    "errorType": "ParseError",
    "errorMessage": "Unexpected token o in JSON at position 1\nAttribute \"reviews\" of type \"S\" has an invalid value of {\"L\":[]}",
    "trace": [
        "ParseError: Unexpected token o in JSON at position 1",
        "Attribute \"reviews\" of type \"S\" has an invalid value of {\"L\":[]}",
        "    at errorHandlingTransform (/var/task/node_modules/dynamoose/dist/Attribute.js:547:23)",
        "    at dedynamofy (/var/task/node_modules/dynamoose/dist/Attribute.js:564:20)",
        "    at Attribute.parseDynamo (/var/task/node_modules/dynamoose/dist/Attribute.js:646:25)",
        "    at Schema.parseDynamo (/var/task/node_modules/dynamoose/dist/Schema.js:196:38)",
        "    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
        "    at async toModel (/var/task/node_modules/dynamoose/dist/Scan.js:51:9)",
        "    at async Promise.all (index 0)",
        "    at async Response.<anonymous> (/var/task/node_modules/dynamoose/dist/Scan.js:197:38)"
    ]
}

CodePudding user response:

You're not escaping the value of images correctly, which is causing other issues i.e. the one you're having.

Change:

"images": {
    "L": [
      {
        "S": "{\"url\":\""}"
      }
    ]
  },

To:

"images": {
    "L": [
      {
        "S": "{\"url\":\"\"}"
      }
    ]
  },

CodePudding user response:

On the line 76, under image According to your schema, inside schema should consists object but it doesn't,

images: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  }

but your data under schema isn't object

    "images": {
      "L": [
        {
          "S": {"url":""}
        }
      ]
    }
  • Related