php - How to set the request body in a json format - Stack Overflow
Changing the Response Body Format
Can someone please explain JSON to me?
Formatting JSON Data for Postman - Stack Overflow
Videos
Factsheet
Two things:
1) You're json encoding an object with a single string but you need to encode an object with an array.
2) You're using http_build_query which will urlencode the array arguments and break the JSON structure.
Do this:
$del = array("delete_list" => [ "8bca1d69c82d939d65ef8ea9a7947bbe" ]);
$j = json_encode(
apiToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$httpHeadersArray = Array();
$httpHeadersArray[] = 'Authorization: key='.$apiToken;
$httpHeadersArray[] = 'Content-Type: application/json';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $curlUrl);
#curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $j);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeadersArray);
$res = curl_exec($ch);
echo "<pre>";
print_r($res);
echo "</pre>";
Throw the header at the top
header('Content-Type: application/json');
I've never worked with any DB or back-end, etc stuff, but I am in need of some sort of data storage. I'm working on a javascript application that will only be run on my pc, offline, and I need to be able to save information. I don't want to rely on localStorage because if the browser history is wiped then all the data goes with it.
While searching for a way to collect and store info, I read about JSON, and it sounded like what I was looking for--and yet I've spent the last 4 hours watching tutorials and so far all I know about it is it's fching JS. I sat through a 12 minute video where all the guy did was write out an object in json and then copy and paste into a js file and said "now you know how to use json in all your future projects" ๐ like what in ACTUAL fk. You could have just WROTE that in js. What's the point of JSON? Everything I've seen or read is practically just the same as this video.
DOES json collect and store data?
Like, if I put an input form in my app, and type a name and hit submit, can I make that Input hardcode into the json file to be saved forevermore and called upon when I needed in this app? Because that's what I need. Any explanation or help on this would be GREATLY appreciated.
We could format/prettify the JSON request body within Postman.
- Paste the JSON request body(raw)
- Select JSON(application/json)
- Press Ctrl + B
When your JSON is validated with JSONLint this is the result:
Error: Parse error on line 1:
{ taco: { name: "",
--^
Expecting 'STRING', '}', got 'undefined'
The object keys should be strings. This is valid JSON:
{
"taco": {
"name": "",
"price": "",
"photo_url": ""
}
}