Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert json to string

Tags:

json

php

mysql

how do i convert a json object to a string

i want to insert a json object to a mysql DB

like image 588
user401000 Avatar asked Jul 31 '10 10:07

user401000


People also ask

Why do we convert JSON to string?

The HTTP does not understand binary format and you can not send JSON object. And that is why it is necessary to convert the JSON object into a string before sending it to the server.

How do I read a JSON file as a string?

We use the readAllBytes() method of the Files class to read bytes data of the JSON files as a string. We store the returned result of the readAllBytes()and get()methods into a variable and return it to the main() method.

Can I convert JSON to txt?

Users can also Convert JSON File to Text by uploading the file. Download converted file with txt extension. JSON to Text Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.

How do I read a JSON file and convert to string in Python?

Load the json file into a file object and read its contents with the file. read() function, which returns a string containing the file's contents. Use the json. loads() function to convert this string object into the required python dictionary and store the result in a variable jsonData.


2 Answers

You might be interested in json_encode().

On the other hand if you already got something json encoded then it already is a string and you can simply store it as-is in the database.

like image 113
VolkerK Avatar answered Sep 19 '22 12:09

VolkerK


JSON itself is a string. People use json_encode() and json_decode() to convert objects/arrays of PHP to string and back to objects/arrays.

like image 30
Ramesh Seera Avatar answered Sep 20 '22 12:09

Ramesh Seera