Trying to display JSON Data, but receiving JSON Parse Error

Asked
Active3 hr before
Viewed126 times

8 Answers

parseerrortryingdisplay
90%

But, I am receiving a JSON Parse Error.,I am trying to display JSON data on my screen, the integer 4 to be exact.,Thanks for contributing an answer to Stack Overflow!

Try the following in your chrome console

let c = {
   "cheetosamount": 4,
   "cookiesvalue": 2
}

c.cheetosAmount
load more v
88%

I am using Outsystems 10 and trying to consume a REST API (single method),I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST API. I used the "TEST" button to validate if it was working - I received a 200 OK message. When I closed the dialog - Oustystems automatically created the Request and Response objects.,I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Pretag
 Pretag team - issue, fix, solve, resolve
72%

The next step is to check if the data we are expecting to see is actually being sent from the server. As shown on the image below, head to the “Network” tab in DevTools, find the request, and click on the “Response” tab.,You have the right to request deletion of your Personal Information at any time.,If your JSON is formatted correctly, then it is time to check what else could be wrong.

Below you can see an example of a JSON format.

{
   "name": "animals",
   "animals": [
      "Dog",
      "Cat",
      "Mouse",
      "Pig",
      "Bear"
   ],
   "hobbies": {
      "football": false,
      "reading": true
   }
}
load more v
65%

The JSON data format is easy for humans to write and read because it is lightweight and text based. With JSON, various data types and simple data structures such as lists and maps can be serialized and represented by strings.,Try it! The following app, its_all_about_you, displays the JSON string for data of various types. Click Run to start the app. Then change the values of the input elements, and check out the JSON format for each data type. You might prefer to open the app in DartPad to have more space for the app’s code and UI.,JSON is text based and human readable.

import 'dart:convert';
load more v
75%

But what if you want to send data to an API?,Let's take a look at JSON objects and JSON arrays and compare them to their JavaScript counterparts.,JSON, or JavaScript Object Notation, is all around us. If you've ever used a web app, there's a very good chance that it used JSON to structure, store, and transmit data between its servers and your device.

{
   "name": "Jane Doe",
   "favorite-game": "Stardew Valley",
   "subscriber": false
}
load more v
40%

JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered. ,SyntaxError: unterminated string literal,Both lines will throw a SyntaxError:

SyntaxError: JSON.parse: unterminated string literal
SyntaxError: JSON.parse: bad control character in string literal
SyntaxError: JSON.parse: bad character in string literal
SyntaxError: JSON.parse: bad Unicode escape
SyntaxError: JSON.parse: bad escape character
SyntaxError: JSON.parse: unterminated string
SyntaxError: JSON.parse: no number after minus sign
SyntaxError: JSON.parse: unexpected non - digit
SyntaxError: JSON.parse: missing digits after decimal point
SyntaxError: JSON.parse: unterminated fractional number
SyntaxError: JSON.parse: missing digits after exponent indicator
SyntaxError: JSON.parse: missing digits after exponent sign
SyntaxError: JSON.parse: exponent part is missing a number
SyntaxError: JSON.parse: unexpected end of data
SyntaxError: JSON.parse: unexpected keyword
SyntaxError: JSON.parse: unexpected character
SyntaxError: JSON.parse: end of data
while reading object contents
SyntaxError: JSON.parse: expected property name or '}'
SyntaxError: JSON.parse: end of data when ','
or ']'
was expected
SyntaxError: JSON.parse: expected ','
or ']'
after array element
SyntaxError: JSON.parse: end of data when property name was expected
SyntaxError: JSON.parse: expected double - quoted property name
SyntaxError: JSON.parse: end of data after property name when ':'
was expected
SyntaxError: JSON.parse: expected ':'
after property name in object
SyntaxError: JSON.parse: end of data after property value in object
SyntaxError: JSON.parse: expected ','
or '}'
after property value in object
SyntaxError: JSON.parse: expected ','
or '}'
after property - value pair in object literal
SyntaxError: JSON.parse: property names must be double - quoted strings
SyntaxError: JSON.parse: expected property name or '}'
SyntaxError: JSON.parse: unexpected character
SyntaxError: JSON.parse: unexpected non - whitespace character after JSON data
SyntaxError: JSON.parse Error: Invalid character at position {
   0
}(Edge)
load more v
22%

Make sure the text is in JSON format, or else you will get a syntax error.,Parse the data with JSON.parse(), and the data becomes a JavaScript object.,Use the JavaScript object in your page:

Pretag
 Pretag team - issue, fix, solve, resolve
60%

Pretag
 Pretag team - issue, fix, solve, resolve

Other "parse-error" queries related to "Trying to display JSON Data, but receiving JSON Parse Error"