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 8310731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:34:05+00:00 2026-06-08T19:34:05+00:00

The json_decode function expects strictly formed JSON and won’t accept values without a key

  • 0

The json_decode function expects strictly formed JSON and won’t accept values without a key however, the way in which I intend to use it the keys don’t matter and repeatedly, manually specifying numerical keys is tedious.

The most obvious answer would be to write my own ‘JSON’ decoder that would intuitively assign numerical keys if they are omitted from the string being decoded. I’m trying to determine if there is a more obvious solution that I am not seeing.


To be more specific, I want to be able to decode a string like:

{"my", "array", "of", "values"}

as if it was written like this

{"0":"my", "1":"array", "2":"of", "3":"values"}

The values of the index are moot. I’ll be using a foreach and the order doesn’t matter, its just extra typing to form my source JSON that way, hence the search for a shortcut.

  • 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-08T19:34:08+00:00Added an answer on June 8, 2026 at 7:34 pm

    You could use the json array structure like this:

    [1,2,3,4,5]

    <?php
    $json = '[1,2,3,4,5]';
    print_r(json_decode($json));
    
    /*
    Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
    )
    */
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function uploadify() { $file = $this->input->post('filearray'); $data['json'] = json_decode($file); print_r($data); $name = $this->$json->{'file_name'}; echo
i have this JSON string that i want to decode it with json_decode(); function
json_decode function is not part of PHP 5.1, so I cannot use it. Is
I have a stdClass object created from json_decode that won't return the right number
i'm trying to use json_decode to combine a few json objects and then re-encode
I have been working on a json decode issue (which I have already had
I'm trying handle bad json data when parsed through json_decode(). I'm using the following
using the below code for decoding json $categories = json_decode($data); $categories = $categories->data; where
Is there a simple alternative to using json_decode function in php versions prior to
I'm making an AJAX request and sending along some JSON: $(function() { var json

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.