Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse vs json_decode

Tags:

json

php

I am currently learning php as I build a database website. I am passing information between functions using JSON objects. I have come across two different functions JSON.parse and json_decode. Please can someone explain to me what the difference is and when I should be using each of them.

Many thanks

like image 492
Ben Thompson Avatar asked Apr 16 '26 09:04

Ben Thompson


2 Answers

The language!

There is no function called JSON.parse in PHP. Also PHP does not have this syntax at all.This is a method of Javascript.

json_decode() is an standard function of PHP and parses JSON to PHP Objects, arrays, etc.

You can see PHP official documentation here for more about json_decode

like image 55
ChrisG Avatar answered Apr 17 '26 23:04

ChrisG


json_decode() is a php function which converts json data into php objects.
json.parse() is a function in javascript which converts json data in javascript objects.

like image 33
Vinod Kumar Avatar answered Apr 17 '26 21:04

Vinod Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!