NbShare
  • Nbshare Notebooks

  • Table of Contents

  • Python Utilities

    • How To Install Jupyter Notebook
    • How to Upgrade Python Pip
    • How To Use Python Pip
  • Python

    • Python Datetime
    • Python Dictionary
    • Python Generators
    • Python Iterators and Generators
    • Python Lambda
    • Python Sort List
    • String And Literal In Python 3
    • Strftime and Strptime In Python
    • Python Tkinter
    • Python Underscore
    • Python Yield
  • Pandas

    • Aggregating and Grouping
    • DataFrame to CSV
    • DF to Numpy Array
    • Drop Columns of DF
    • Handle Json Data
    • Iterate Over Rows of DataFrame
    • Merge and Join DataFrame
    • Pivot Tables
    • Python List to DataFrame
    • Rename Columns of DataFrame
    • Select Rows and Columns Using iloc, loc and ix
    • Sort DataFrame
  • PySpark

    • Data Analysis With Pyspark
    • Read CSV
    • RDD Basics
  • Data Science

    • Confusion Matrix
    • Decision Tree Regression
    • Logistic Regression
    • Regularization Techniques
    • SVM Sklearn
    • Time Series Analysis Using ARIMA
  • Machine Learning

    • How To Code RNN and LSTM Neural Networks in Python
    • PyTorch Beginner Tutorial Tensors
    • Rectified Linear Unit For Artificial Neural Networks Part 1 Regression
    • Stock Sentiment Analysis Using Autoencoders
  • Natural Language
    Processing

    • Opinion Mining Aspect Level Sentiment Analysis
    • Sentiment Analysis using Autoencoders
    • Understanding Autoencoders With Examples
    • Word Embeddings Transformers In SVM Classifier
  • R

    • DataFrame to CSV
    • How to Create DataFrame in R
    • How To Use Grep In R
    • How To Use R Dplyr Package
    • Introduction To R DataFrames
    • Tidy Data In R
  • A.I. News
NbShare Notebooks
  • Publish Your Post On nbshare.io

  • R Python Pandas Data Science Excel NLP Numpy Pyspark Finance

JSON Parse Error Syntax Error Unexpected token N In JSON

You will see following error if json String contains values other string or numbers. For example it can happen if you are parsing the data from the Ajax request.

In [1]:
let jsonString = '{"name":"John", "age": 5, "name":"Alex", "age":NaN}';
In [2]:
JSON.parse(jsonString);
undefined:1
{"name":"John", "age": 5, "name":"Alex", "age":NaN}
                                               ^

SyntaxError: Unexpected token N in JSON at position 47
    at JSON.parse (<anonymous>)
    at evalmachine.<anonymous>:1:6
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at run ([eval]:1020:15)
    at onRunRequest ([eval]:864:18)
    at onMessage ([eval]:828:13)
    at process.emit (node:events:526:28)
    at emit (node:internal/child_process:938:14)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

To fix this remove the value which is not a string or number. We can replace the value with null, null is valid keyword.

In [3]:
let cleanedJsonString = jsonString.replace(/NaN/g, 'null');

Let us try now to parse the cleaned json string.

In [4]:
JSON.parse(cleanedJsonString);
Out[4]:
{ name: 'Alex', age: null }

Related Notebooks

  • How To Solve Error Numpy Has No Attribute Float In Python
  • How To Fix Error Pandas Cannot Open An Excel xlsx File
  • ERROR Could not find a version that satisfies the requirement numpy==1 22 3
  • How To Parse Yahoo Finance News Feed With Python
  • How To Read JSON Data Using Python Pandas
  • Json Python
  • Boxplots In R
  • Append In Python
  • Dictionaries In Python

Register

User Already registered.


Login

Login

We didn't find you! Please Register

Wrong Password!


Register
    Top Notebooks:
  • Data Analysis With Pyspark Dataframe
  • Strftime and Strptime In Python
  • Python If Not
  • Python Is Integer
  • Dictionaries in Python
  • How To install Python3.9 With Conda
  • String And Literal In Python 3
  • Privacy Policy
©