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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:40:19+00:00 2026-06-11T15:40:19+00:00

I am having issues with validating the output of my json_encode() function. I am

  • 0

I am having issues with validating the output of my json_encode() function.

I am pulling in an XML feed with cURL, converting it into an array, and converting that array into JSON with json_endode(). Ill spare you the cURL stuff:

  foreach ($xmlObjects->articleResult as $articleResult) {
    $article = array(
      "articleResult" =>
      array(
        'articleId' => (string)$articleResult->articleId,
        'title' => (string)$articleResult->title,
        'subhead' => (string)$articleResult->subhead,
        'tweet' => (string)$articleResult->tweet,
        'publishedDate' => (string)$articleResult->publishedDate,
        'image' => (string)$articleResult->image
      ),
    );
    $json = str_replace('\/','/',json_encode($article));
    echo $json;
  }

Which is giving me a JSON readout of:

{
    "articleResult": {
        "articleId": "0001",
        "title": "Some title",
        "subhead": "Some engaging subhead",
        "tweet": "Check out this tweet",
        "publishedDate": "January 1st, 1970",
        "image": "http://www.domain.com/some_image.jpg"
    }
}
{
    "articleResult": {
        "articleId": "0002",
        "title": "Some title",
        "subhead": "Some engaging subhead",
        "tweet": "Check out this tweet",
        "publishedDate": "January 1st, 1970",
        "image": "http://www.domain.com/some_image.jpg"
    }
}

This will give me a JSONLint error saying:

Parse error on line 10:
..._120x80.jpg"    }}{    "articleResult
---------------------^
Expecting 'EOF', '}', ',', ']'

So naturally I will add in the comma, which gives me an End of File expectation:

Parse error on line 10:
..._120x80.jpg"    }},{    "articleResu
---------------------^
Expecting 'EOF'

I am new to JSON, but I have checked the website and a few resources for proper JSON formatting and structure, and from what I can see my readout is following the guidelines. Any pointers?

Resources I’ve checked:

JSON.org naturally

Wikipedia has well documented page

W3Resource Had a good explanation of structure.

JSONLint

  • 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-11T15:40:20+00:00Added an answer on June 11, 2026 at 3:40 pm

    You were encoding 2+ objects into json string, you need [ ] to wrap them

    the correct syntax is

    [ 
       { /* first object */ }
     , { /* second object */ }
     , { /* third object */ }
    ]
    

    the things you need to look out are

    • [ ] wrap
    • separate objects by comma

    Solution

    $json = array();
    foreach ($xmlObjects->articleResult as $articleResult) {
      $article = array(
        "articleResult" =>
        array(
          'articleId' => (string)$articleResult->articleId,
          'title' => (string)$articleResult->title,
          'subhead' => (string)$articleResult->subhead,
          'tweet' => (string)$articleResult->tweet,
          'publishedDate' => (string)$articleResult->publishedDate,
          'image' => (string)$articleResult->image
        ),
      );
      $json[] = $article;
    }
    echo json_encode($json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues with validating an array property in Mongoose. When I use
I have the following code which returns a JSON array. I'm having issues putting
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
I am having issues passing a dynamic parameter to a JavaScript function using innerHTML.
I wrote this validation method but am having issues with it. function validate_password(pwd) {
I am having issues with ie 8 compatibility mode. I have some buttons that
I'm having issues with schema validation, this is my xml <?xml version=1.0 encoding=utf-8 ?>
I'm having issues validating with cocoon and the number of fields a model is
I'm having some issues in validating things using expressjs and mongodb. This is the
Having issues with Twitter Bootstrap responsive navigation. The best way to explain this is

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.