Invalid type. Expected String But Got Null - Parse JSON Error

Introduction

When trying to use parse JSON I am getting the following schema error.

The use case here is there is a CSV file, which gets uploaded to SharePoint document library, when it gets uploaded the flow triggers and gets the file content of CSV into an array using ‘select’ operation. The details are explained below in the article.

However, when generating schema using Parse Json, I am getting the above error, “Invalid Type, Expected string but got Null.’

The issue here is in the CSV input file, the flow is expecting of data type string, but got null values for some fields. The trick here is if the last row of CSV is empty then you would probably end up throwing this error. There are some tips from community experts, where it is required to update the schema to allow null values for the fields. Please look into the references blog on how to get this done.

But in my case, it happened since there is an empty row in CSV. To identify, open the CSV in notepad and you should see empty space as shown in the below screen capture.

I deleted the last row from CSV and boom the issue is solved. I was able to get the schema generated successfully using ‘Parse Json’.

Invalid type. Expected String but got Null - Parse Json Error

Hope this helps someone who is facing a similar issue.

References

https://www.sharepointsiren.com/2018/10/flow-parse-json-null-error-fix/?unapproved=3051&moderation-hash=158d090c5f1b1f6344fb44f7358d3b21#comment-3051