Merge two Json Object PHP (not same estructure)

  array-merge, json, laravel, php

Hello i have a two json object’s

Json 1

{
  "id": null,
  "type": "NE",
  "info": {
    "name": "Ne",
    "last_name: "NE",
    "status": "NE",
    "rfc": "NE",
    "email": "jNE"
   }
  }

json 2

  {
  "id": 2,
  "type": "PF",
  "info": {
    "status": 1,
    "rfc": "DOSLWOOEOE22",
    "email": "[email protected]"
   }
  }

I need merge the json object’s, when json 2 override the values in json 1, but the json result contain the keys/values that the json does not have

i need the json result same this:

 {
  "id": 2,
  "type": "PF",
  "info": {
    "name": "Ne",
    "last_name: "NE",
    "status": 1,
    "rfc": "DOSLWOOEOE22",
    "email": "[email protected]"
   }
  }

**note: i try using array_merge but doesn’t work, only override json 2 into json 1 without another keys **

Source: Laravel

Leave a Reply