How to Merge Two JSON Strings into One with PHP
Hi! In this tutorial we will see how to merge two json strings into one in php . People often mistakes JSON for object or array but it's the string representation of a JavaScript object. In a recent project, I wanted to combine two jsons. That is, I have to make two API calls and combine their results into one. It is a rest api and returns the response as json. The task is simpler than I thought. It employs a similar technique I used here earlier when dealing with json. Let me show you how to do it. PHP - Merging Two JSON into One: If you are new to working with JSON, don't worry. PHP offers native functions to handle it easily. The idea is to decode the json data, write it to an array and encode it back to json. Below are the steps involved in the process. STEP-1) Let's take two different jsons containing couple of employee details. <?php $json1 = '{"id": "GD01", "name": "Garrett Davidson", "position...