How to fix invalid / devoid json?

I have a problem with JSON. Before we discovered the error, the column data in the mysql database was of type VARCHAR (255), where the serialized json was stored. About 2 months it worked well, but when the project began to grow, 255 characters - it was not enough. But we forget to change the type to TEXT. Now we have a problem that our serialized json is disabled up to 255 characters and is now invalid. I don't care about lost data, but I need to make minimal parsed / valid json.

for ex:

data = '{"state_id":[null,20],"dispatcher_id":[null,6057525],"uir":[null,{"level":"2"'

I need to do it right, for example

data = '{"state_id":[null,20],"dispatcher_id":[null,6057525],"uir":[null,{"level":"2"}]}'

add }]} to the end of json.

Is there any quick way to do this? Or should I write my own parser / commit?

+4
source share
2 answers

I completed this task, so I want to share my solution

0
source

You can use jsonlist

This is a pure JavaScript implementation for checking JSON.

According to the check, you will find out what is missing at the end, and add the missing value. you can also check out the demo online

0
source

Source: https://habr.com/ru/post/1497014/


All Articles