Skip to content

Instantly share code, notes, and snippets.

@azazqadir azazqadir/

Created Oct 27, 2018
What would you like to do?
Parsing Data in JSON in Codeigniter

You can use Codeigniter curl library to parse data in JSON format. For this you can use POST request.

Add this to your JSON file


$url = '';

$formatJsondata = array(

   'username' => 'authenticate-username',

   'password' => 'password-authentication'


$encodedJsonData = json_encode($formatJsondata);


$this->curl->option(CURLOPT_HTTPHEADER, array('Content-type: application/json; Charset=UTF-8'));


echo $result = $this->curl->execute();

To show data, add this to config.php file

Class MY_Loader extends CI_Loader {

public $_json_array = array();

public function __construct() {


$this->ci = &get_instance();


public function view($view, $vars = array(), $return = FALSE) {

$format = $this->ci->input->get('format');

if($format == 'json') {

$this->ci->_json_array[$view] = $vars;


->set_output(json_encode($this->ci->_json_array, JSON_NUMERIC_CHECK));


else {

parent::view($view, $vars, $return);



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.