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

  • Home
  • SEARCH
  • 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 8594599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:14:10+00:00 2026-06-12T00:14:10+00:00

I have an array in the database and it looks like this: {hello:world, Test:[hello]}

  • 0

I have an array in the database and it looks like this: {"hello":"world", "Test":["hello"]}, which is perfect for JSON.stringify, but when I select it from the database like this:

$metadata = $this->repository->getMetadata($id);

$data = json_encode($metadata);

return $this->render('AcmeQuotesBundle:Home:metadata.html.twig', array('data' => $data));

and put this in the template:

{% block body %}
    <script>
        var obj = {{ data|raw }}

        document.body.innerHTML = "";
        document.body.appendChild(document.createTextNode(JSON.stringify(obj, null, 4)));
    </script>
{% endblock %}

I get this output:

[
    {
        "quoteMetadata": "{\"hello\":\"world\", \"Test\":[\"hello\"]}"
    }
]

which is not what I want. All I want is the value of obj to be the native string – {"hello":"world", "Test":["hello"]} without "quoteMetadata":, without the quotation marks and without the "\" around the words. I tried using implode(), but I get notice:

Notice: Array to string conversion in C:\xampp\htdocs...

I’m using Symfony2, Twig and Doctrine2 and I’m doing all this because I want the string from the database to be shown in a easy for reading way like here – http://jsfiddle.net/AndyE/HZPVL/ If you have any ideas how to fix this or how to make it in another way, plase share!


EDIT

When I put var_dump($matadata) after $metadata = $this->repository->getMetadata($id);, I get this:

array(1) { [0]=> array(1) { ["quoteMetadata"]=> string(35) "{"hello":"world", "Test":["hello"]}" } } 
  • 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-12T00:14:11+00:00Added an answer on June 12, 2026 at 12:14 am

    The issue is your metadata array isn’t clean; the bit you want is buried in an associative array inside a single-row array. So try:

    $metadata = $this->repository->getMetadata($id);
    return $this->render('AcmeQuotesBundle:Home:metadata.html.twig', array('data' => $metadata[0]['quoteMetadata']));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have an array that looks like this, Array ( [cfi_title] => Mr
i have an array of data from from my database, it looks like this
I have written a function to print database table to an array like this
I have a list of recipes obtained from a database that looks like this:
I have an array being returned from the database that looks like so: $data
I have an array that looks something like this array( 'cars' => 10, 'trucks'
I have a binary, the database table of relationships looks like this: +----+----------+---------+-----+ |
I have a database that looks like this: I can generate a tree from
So in javascript I have an array that looks about like this: [{x1:0,x2:2000,y:300},{x1:50,x2:250,y:500}] And
I have written a query with codeigniters database library, it looks like this, public

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.