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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:37:31+00:00 2026-06-09T06:37:31+00:00

Could anyone assist me with how I can pass one JSON object as a

  • 0

Could anyone assist me with how I can pass one JSON object as a field to another without having quotes added? Basically I have a function that needs to be able to append a ‘header’ to a set of data pre parsed into JSON in some cases or just parse the data in others.

Problem is everything works fine until I try to pass a JSON object to be stored as a “payload” for a header, at which point the JSON becomes invalid because of the extra set of quotations attached.

The object that I am trying to use is:

{
    "header": {
        "table": "user",
        "action": "insert",
        "opType": "string",
        "message": "Insert sucessful for user: 6",
        "start of records": false,
        "end of records": true
    },
    "data": "[
        {
            "id": "6",
            "Surname": "Peter",
            "Forename": "Kane",
            "Email": "pkane@a.co.uk",
            "Personal_Email": "p.kane@gmail.com",
            "Home_Phone_No": "01216045429",
            "Work_Phone_No": "087852489",
            "Mobile_Phone_No": "77245455598",
            "Address_Line_1": "1aplace",
            "Address_Line_2": "thistown",
            "Address_Line_3": "Someplace",
            "Address_Line_4": "whereever",
            "Post_Code": "W549AJ",
            "Mode_ID": "44",
            "Route_ID": "g12",
            "image": ""
        }
    ]"
}

The problem is the quotes after the “data” key and before the last curley brace without these everything validates fine.
As I’ve said Im using PHP Ive tried regex expressions substring etc but nothing seems to work.

my PHP is as follows:

 public function dataToJSON($operationType, $table, $action, $data, $message, $header = true, $firstRecord = null) {

    if ((!($operationType) === 'recordSet') and (!($operationType === 'error')) and (!($operationType === 'string') )) {
        throw new Exception("Operation type:" . ' ' . $operationType . ' ' . 'passed to the dataToJSON function not recogonised');
    }

    if (!(is_null($firstRecord))) {

        $isFirstRecord = $firstRecord;
        $isLastRecord = !$firstRecord;
    } else {
        $isFirstRecord = false;
        $isLastRecord = false;
    }

    if ($header) {
        $jsonData = array('header' => array(
                'table' => "$table",
                'action' => "$action",
                'opType' => "$operationType",
                'message' => "$message",
                'start of records' => $isFirstRecord,
                'end of records' => $isLastRecord),
        );
    } else {
        $jsonData = array();
    }

     $recordSet = array();

    if ($operationType === 'recordSet') {
        while ($row = mysql_fetch_assoc($data)) {
            array_push($recordSet, $row);
        }
        if ($header) {
            $jsonData ['data'] = $recordSet;
            return json_encode($jsonData);
        } else {
            return json_encode($recordSet);
        }

    } else if (($operationType === 'error') || ($operationType === 'string')) {
        if ($header) {
            $jsonData ['data'] = $data;
            return stripslashes(json_encode($jsonData));
        } else {
            return $data;
        }
    }
}
  • 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-09T06:37:33+00:00Added an answer on June 9, 2026 at 6:37 am

    A JSON object is nothing more than a mere string. To achieve what you are trying to achieve, you would probably need to decode and then re-encode your JSON string:

    $jsonData['data'] = json_decode($data, TRUE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

could anyone assist me with this. I need to compare two beefy xml files
I was wondering whether anyone could assist me. When the user clicks the menu
could anyone please clarify the meaning of line generalizes the tag object's storage of
Hi everyone I am stack so if anyone can assist in any way it
Can anyone assist me in getting a Python script running on Hostgator Shared hosting?
Could anyone assist me with this Jigomerge error in Jenkins? I'm sure its probably
I wonder if anyone could assist? Table_A below shows an example product in my
could anyone assist in authenticating to photobucket and uploading an image from and iPhone
could anyone assist in authenticating to photobucket and uploading an image from and iPhone
Could anyone guide me in created a simple app in JS? What the app

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.