Home » Php » php – YAML parsing error – multidimensional arrays

php – YAML parsing error – multidimensional arrays

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am getting this exception, which indicates a malformed parameters file:

[Symfony\Component\Config\Exception\FileLoaderLoadException]                                                                                                                    
  Cannot import resource "XXX/app/config/parameters_testing.yml" from "XXX/app/config/config_dev.yml".     
(Malformed inline YAML string { id: 212, status: 3, events:[ at line 168 (near "- { id: 212, status: 3, events:["))

I am trying to nest arrays into arrays and so on, but I cannot find any helpful resource and keep getting exceptions.

cases:
    - { id: 213, status: 1}
    - { id: 213, status: 3, events:[
          { rec: both, event: 34}
          { rec: odd, event: 1}
          { rec: even, event: 2}
          { rec: odd, event: 29}
          { rec: odd, event: 9}
          { rec: even, event: 3}
          { rec: odd, event: 27}
          { rec: even, event: 27}
        ]
      }

Any suggestions would be appreciated.

How to&Answers:

Further to the accepted answer, a more readable way would be to take it out of inline like…

cases:
    - 
        id: 213
        status: 1
    - 
        id: 213
        status: 3
        events:
            - { rec: both, event: 34} 
            - { rec: odd, event: 1 }
            - { rec: even, event: 2 }
            - { rec: odd, event: 29 }
            - { rec: odd, event: 9 }
            - { rec: even, event: 3 }
            - { rec: odd, event: 27 }
            - { rec: even, event: 27 }

Answer:

If you declare inline, you must make it on 1 line

cases:
    - { id: 213, status: 1}
    - { id: 213, status: 3, events:[ { rec: both, event: 34} , { rec: odd, event: 1} , { rec: even, event: 2}, { rec: odd, event: 29} , { rec: odd, event: 9}, { rec: even, event: 3},  { rec: odd, event: 27},  { rec: even, event: 27}  ]}