Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML parsing error - multidimensional arrays

Tags:

php

yaml

symfony

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.

like image 798
thitami Avatar asked Jun 03 '15 14:06

thitami


2 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 }
like image 153
qooplmao Avatar answered Nov 16 '22 23:11

qooplmao


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}  ]}
like image 3
Med Avatar answered Nov 16 '22 21:11

Med