Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert php json array into yaml

How to Convert PHP array into YAML as we convert PHP array into JSON using json_encode. Is their any function using which we can convert PHP array into YAML

like image 995
Pallavi Avatar asked May 13 '16 06:05

Pallavi


People also ask

Can I convert JSON to YAML?

Users can also Convert JSON File to YAML by uploading the file. When you are done with JSON to YAML converting. You can download as a file or create a link and share. JSON to YAML Transformer works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.

How do you write an array of objects in YAML?

An array is a group of similar values with a single name. In YAML, Array represents a single key mapped to multiple values. Each value starts with a hyphen - symbol followed by space. In a single line, write the same thing above using 'square brackets syntax.

How do you represent a list of items in YAML?

The block sequence style of YAML uses hyphens or dashes to ( - ) to represent arrays. A hyphen ( - ) followed by white space ( ) represents an element of an array. When you enter the dashes, you need to ensure that all items are at the same indentation level. See the code example below to understand this better.

What is YAML in PHP?

YAML is a human-readable data-serialization mark-up language. It is better than another mark-up language, XML to store the data because YAML content is easy to read and write. YAML syntax rules are used to create a YAML file that is a text file with the extension “.


1 Answers

You use Yaml PECL package, but this may not always be possible (e.g on shared hosting) since it's not bundled with PHP by default.

Other solution may be to use some PHP library like Symfony's Yaml Component

like image 181
Jakub Matczak Avatar answered Oct 08 '22 04:10

Jakub Matczak