Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:15:22+00:00 2026-06-04T21:15:22+00:00

I am using CodeIgniter for some small REST WS, and can not get a

  • 0

I am using CodeIgniter for some small REST WS,
and can not get a properly (as viewed from Jackson parser point of view)
formatted JSON output. For Jackson to do it, the output needs to be something like:

{ "recipes": 
    [ 
        {
            "name":"Recipe 1",
            "id":"8aecfd9b2fa26e83012fa298c2a50017",
            "recipe":"1 Lorem ipsum...",
        }, 
        { 
            "name":"Recipe 2",
            "id":"8aecfd9b2fa26e83012fa298c2a90018",
            "recipe":"2 Lorem ipsum...",
        },
        {
            "name": "Recipe 3",
            "id":"8aecfd9b2fa26e83012fa298c2ae0019",
            "recipe":"3 Lorem ipsum...",
        } 
    ]
}

And using the code in CodeIgniter controller like:

        $allEecipes['recipes'] = array(
                    array('name' => 'Recipe 1', 'id' => '8aecfd9b2fa26e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
                    array('name' => 'Recipe 2', 'id' => '128aecfd9b226e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
                    array('name' => 'Recipe 3', 'id' => '34ecfd9b2fa26e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
        );      

        $this->response($allEecipes, 200); // 200 being the HTTP response code

I get the following JSON output:

[
  [
    {
      "name": "Recipe 1",
      "id": "8aecfd9b2fa26e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    },
    {
      "name": "Recipe 2",
      "id": "128aecfd9b226e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    },
    {
      "name": "Recipe 3",
      "id": "34ecfd9b2fa26e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    }
  ]
]

Notice the brackets, and the missing name for an array.
How to get things right? I suppose the PHP encode_to_json is
doing it’s job correctly.

EDITED:
Still no luck, after adding class like

class Eecipes
{
    public $recipes;

    public function __construct()
    {
    }
}

And creating it like

    $allEecipes = new Eecipes();
    $allEecipes-> recipes = array(
        array('name' => 'Recipe 1', 'id' => '8aecfd9b2fa26e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
        array('name' => 'Recipe 2', 'id' => '128aecfd9b226e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
        array('name' => 'Recipe 3', 'id' => '34ecfd9b2fa26e83012fa298c2a50017', 'recipe' => '1 Lorem ipsum...'),
        );
$this->response($allEecipes, 200);

The output I get is

{
  "recipes": {
    "0": {
      "name": "Recipe 1",
      "id": "8aecfd9b2fa26e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    },
    "1": {
      "name": "Recipe 2",
      "id": "128aecfd9b226e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    },
    "2": {
      "name": "Recipe 3",
      "id": "34ecfd9b2fa26e83012fa298c2a50017",
      "recipe": "1 Lorem ipsum..."
    }
  }
}

So, still not as needed. No angled brackets [, and the numbers are not needed.
And the result in online JSON viewer shows the difference, too

The good:
http://img822.imageshack.us/img822/7034/goodj.jpg

and the bad:
http://img534.imageshack.us/img534/3389/badrk.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:15:25+00:00Added an answer on June 4, 2026 at 9:15 pm

    Try encoding your result yourself with json_encode
    and then send the result ?
    Look at the flag options of json_encode, JSON_FORCE_OBJECT might help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this syntax for grabbing some data from database, I using codeigniter's active
I'm using Codeigniter not for so long but I've some charset problems.. I'm asking
I've been using CodeIgniter for some quite time, and I've been extremely happy with
I'm using Codeigniter to insert some data into a MySQL table. However, the single
Hi I am using CodeIgniter with DataMapper and really need some help defining relationship
Im carrying out some form validation with codeigniter using a custom validation callback. $this->form_validation->set_rules('testPost',
I am using CodeIgniter framework for PHP . There are some pages that are
I'm writing a CRUD system using CodeIgniter, implementing some 'one to many' dependencies between
I am using codeigniter framework and in view i am using jquery. Now, I
I m using codeigniter and would like to grab some user info with ajax.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.