Introducing Neon to YAML Converter

I wrote about How to migrate between Neon to Yaml almost a year ago. Recently we needed to migrate many files with parameters, imports, and mainly services.

Neon and YAML are basically arrays, right? So why not let a tool let do the dirty work?

When Do You need it?

How to Use it?

To use Symplify/NeonToYamlConverter, require it a composer dependency:

composer require symplify/neon-to-yaml-converter --dev

Run it on one file or directory - it takes all *.neon, *.yml and *.yaml files:

vendor/bin/neon-to-yaml-converter convert file.neon

The 2 Most Problematic Places Converter Tool Handles

In Neon there are nested parameters = you can use %payu.user% to get parameter user in payu array. In YAML used in Symfony code, there are only one level parameters. That means you can use only the payu parameter, nothing nested.

That's why all parameters have to be converted to the single level of nesting, here to payu_user:

 parameters:
-    payu:
-       user: Pepa
+    payu_user: Pepa
-       password: abz123
+    payu_password: abz123

 services:
     PayuService:
         arguments:
-            - '%payu.user%'
+            - '%payu_user%'
-            - '%payu.password%'
+            - '%payu_password%'

Another case are Neon entities. Their goal is to make syntax short. Its cost is less readability.

Code is actually parsed to an object, that has different meaning in different places:

 services:
-    - App\SomeService(@anotherService, %perex%)
+    App\SomeService:
+        arguments:
+            - @anotherService
+            - %perex%

Those of you who don't use Neon for years, would you guess that?

All this converter handles for you.


Next time you migrate your config, package or whole application from Neon to YAML, let Symplify\NeonToYamlConverter do the work for you.

Happy coding!


Found a typo? Fix it to join team of 64 people that improve content here

❤️️ Do you like what I write about? Or do you hate it but enjoy discussion? 😠
You can support my writing by throwing a couple bucks at my Patreon