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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:01:13+00:00 2026-05-16T20:01:13+00:00

I am trying to create JSON from a comma delimited string, the string look

  • 0

I am trying to create JSON from a comma delimited string, the string look something like this:

One,Two,Three,Four,Five,Six,Seven

I need it to look something like this:

[{"test":"One"},{"test":"Two"},{"test":"Three"},{"test":"Four"},{"test":"Five"},{"test":"Six"},{"test":"Seven"}]

Here is the code I have thus far:

$string = mysql_fetch_array($test, true);
$woot = explode(',', $string['test']);

$json = json_encode($woot);
echo($json);

Thanx in advance!

  • 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-05-16T20:01:14+00:00Added an answer on May 16, 2026 at 8:01 pm

    json_encode() will turn a PHP array into a JS array or object.

    What this means is that your JSON output will probably look something like this:

    ['One','Two','Three','Four','Five','Six','Seven']
    

    ie because your PHP array is a simple numeric-keyed array, it converts into a basic JS array.

    The desired output is similar, except that each array element is in the form {‘key’:’value’} rather than just ‘value’. This means that wach array element is an object (albeit one with a single key).

    To produce this, you will need to adapt your PHP code after the explode, to loop through each array element and turn it into a nested array. Something like this:

    foreach($woot as $key=>$value) {$woot[$key]=array('test'=>$value);}
    

    …and then pass $woot to json_encode() as before.

    That will produce pretty much the output you’re looking for. Not sure why you’d want to encode it like that though — are all those test objects really required? Are you passing into an existing JS program that requires this format? It looks a bit of a messy structure, so if so, there’s probably some JS code that could do with tidying up!

    Hope that helps.

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

Sidebar

Related Questions

I'm trying to create a JSON object that looks like this: { request_type:send_string security_level:0
I am trying to create a treeview like structure from JSON data . Structure
I am trying to create a json file from a rake task using rabl.
I'm trying to read data from a service (returns JSON object) and create an
I am trying to add string values in JsonArray and after that create Json
I have created this jsfiddle: http://jsfiddle.net/mfnxm/1/ I am trying to create this JSON: [{
I am trying to create a Nuget package from my project following this guide
I'm trying to create a json object from MySQL results, but not getting the
I'm trying to write/create a JSON file from a AIR app, I'm trying not
I am trying to create a multiselect list from json store, which is in

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.