mysql: Invalid JSON text in argument 1 to function json_extract: “Invalid value.” at position 3333

I need to save the next data in a json table:

[
    {
        "company": 2,
        "employee": {
            "payroll": 1,
            "id":130434
            },
        "resources": {
            "lastname": "Garcia",
            "name": "Luis"
        }
    }
]

The problem is when I define my columns, because I receive my json with different data hierarchy, My actual code, especifically in the table I built is:

 
select * from json_table('$Employees', '$[*]' columns(
   payroll Int path '$.payroll',
   ID Int path '$.id',
   lastname varchar(100) path '$.lastname',
   name varchar(100) path '$.name'
     ) 

but I am still getting error: “Invalid JSON text in argument 1 to function json_extract: “Invalid value.” at position 333.”

What would be the correct structure of my fields in my json_table

I tried to save my json in a table but the json contains different data hierarchy and my fields in my json table I think not contain the correct structure to save.

  • Shown “json” value is NOT valid from MySQL looking point.

    – 

  • You have an extra comma after the last key/value in each object. Like "id":130434, should not have a comma after it, because it’s the last key/value in the object. Like in many other programming languages, there is no comma allowed after the last item in a list.

    – 

  • Thanks @BillKarwin Now I delete from my example

    – 

Leave a Comment