Converting JSONL to Array with PHP


The json_decode function can be used as shown below −

json_decode($json_string_that_needs_to_be_converted, true);

The below lines of code can be used to convert JSONL to array format −

$json_string = '["m@gmail.com","p@gmail.com","q@gmail.com"]';
$array_of_data=json_decode($json_string);

An alternate is to use the below code, wherein the way json_string has been defined changes −

Example

$json_string = "[\"m@gmail.com\",\"p@gmail.com\",\"q@gmail.com\"]";
$array_of_data=json_decode($json_string);

Output

This will produce the following output −

Array("m@gmail.com","p@gmail.com","q@gmail.com")

Updated on: 06-Apr-2020

270 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements