Laravel 5.3 update field JSON MySql - # 3143 - Invalid JSON path expression

2

Query generated by laravel:

update 'informations' set 'parameters' = json_set('parameters', "$.'Campo teste'.type", 'string'), 'parameters' = json_set('parameters', "$.'Campo teste'.value", 'Novo valor') where 'parameters'->'$."Identificação do campo"."type"' = 'string' and 'parameters'->'$."Identificação do campo"."value"' = 'D25L'

Syntax laravel:

DB::table("informations")->where($data['where'])->update($data['update']);

MySql returns me the following error:

#3143 - Invalid JSON path expression. The error is around character position 7.

Array code $ data:

{
   "update": {
      "parameters->'Campo teste'->type": "string",
      "parameters->'Campo teste'->value": "Novo valor"
   },
   "where": {
      "parameters->Identificação do campo->type": "string",
      "parameters->Identificação do campo->value": "D25L"
   }
}

Note:

If I do a simple query using only the excerpt from where it finds the records, I believe the problem is in JSON_SET  even

    
asked by anonymous 24.08.2017 / 18:16

1 answer

3

I made a change to the laravel file MySqlGrammar.php located at:

vendor\laravel\framework\src\Illuminate\Database\Query\Grammars

Line 155 Method compileJsonUpdateColumn

From:

$accessor = '"$.'.implode('.', $path).'"';

for

$accessor = "'$.".implode('.', $path)."'";

And in my array in the update I added double quotation marks:

    "update": {
      "parameters->\"Campo teste\"->type": "string",
      "parameters->\"Campo teste\"->value": "Novo valor"
   }
    
24.08.2017 / 20:22