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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:15:02+00:00 2026-06-10T04:15:02+00:00

If a JSON string has spaces in its name Some Items (is there a

  • 0

If a JSON string has spaces in its name "Some Items" (is there a more accurate term for this?), how do you access it in PHP after using json_decode($json_string) on it? Is this name even required for data returned from an API?

JSON String

{"Some Items":[{"post_id":"1284"},{"post_id":"1392"},{"post_id":"1349"}]}

These doesn’t work

$data = json_decode($json_string);
$data = $data->"Some Items";    // invalid PHP
$data = $data["Some Items"];    // Cannot use object of type stdClass as array
  • 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-10T04:15:04+00:00Added an answer on June 10, 2026 at 4:15 am

    If you don’t like the curly braces idea you can use the dynamic accessor business:

    $someitems = "Some Items";
    var_dump($data->$someitems);
    

    Or, you could cast $data to an array and use the square brackets:

    $data = (array)json_decode($json_str);
    var_dump($data['Some Items']);
    

    json_decode has a switch so you don’t need to use casting.

    $data = json_decode($json_str, true);
    var_dump($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I decode this JSON String which has been received as a parameter
Example JSON (note that the string has trailing spaces): { aNumber: 0, aString: string
I'm trying to append a JSON string into a file which has already more
I have a json string like this [ { name:sourabh, userid:soruabhbajaj, id:11, has_profile_image:0 },
I have JSON string that has nested objects with dynamic names that vary each
I have a JSON string (external file) which has an element which can either
I have the following JSON String { name:Product, properties: { id: { type:number, description:Product
I have the following JSON string (from wikipedia http://en.wikipedia.org/wiki/JSON ) { name:Product, properties: {
I have a json string like this: { d: { results: [ { __metadata:
I'm receiving a JSON string in a PHP page : $JSON = $_POST['submit']; $Array

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.