Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Fetch value from json in mysql drupal 8JSON

Source Link

Fetch value from json in mysql drupal 8

I have a field in drupal "field_xyz". it stores json values. JSON looks like this:

{"Id_-_SiteWasteProductAction":"34638393224", "Postcode": "CSF 12CF"}

I want to fetch postcode value from this json using mysql query

i used

$query = $connection->query("SELECT @@sql_mode"); //for group by (php 7.0)
$query = $connection->query("set @@sql_mode=''"); //for group by (php 7.0)
$query = $connection->select('node_revision', 'n');
$query->fields('n', ['vid', 'nid']);
$query->fields('shad', ['field_xyz_value']);
$query->join('node__field_xyz', 'shad', 'n.vid = shad.revision_id'); 

i fetch postcode value from url-

   $filter_postcode_value = \Drupal::request()->query->get('filter_postcode_value');//postcode

and i use this condition

   if(!empty($filter_postcode_value)){
          $query->condition('an.field_xyz_value->"$.Postcode"', '%' . db_like($filter_postcode_value) . '%' ,'LIKE');   
     }

output is coming out as-

    Column not found: 1054 Unknown column 'shad.field_sheet_all_data_value.Postcode

Please help!