crdoconnor / strictyaml

Type-safe YAML parser and validator.
https://hitchdev.com/strictyaml/
MIT License
1.47k stars 60 forks source link

Support request: Sequence of sequences #74

Open fkromer opened 5 years ago

fkromer commented 5 years ago

Does StriclYaml support nested sequences like e.g. seq_of_seqs

seq_of_seqs:
  -
    - "a"
    - "b"
  -
    - 1
    - 2

I could not find a corresponding section in the sequences docs.

crdoconnor commented 5 years ago

Hi. You should be able to Seq(Seq(Str())), no?

crdoconnor commented 5 years ago

Yep, it works:

In [1]: from strictyaml import Seq, Str, load                                                                                                                                                                      

In [2]: load(""" 
   ...: - 
   ...:   - 1 
   ...:   - 2 
   ...:   - 3 
   ...: - 
   ...:   - f 
   ...:   - 5 
   ...:   - 6 
   ...: """, Seq(Seq(Str())))                                                                                                                                                                                      
Out[2]: YAML([['1', '2', '3'], ['f', '5', '6']])
crdoconnor commented 5 years ago

Leaving this open for now as I should probably add an example of this to the docs.

fkromer commented 5 years ago

Yes, works perfectly fine. Sorry. I forgot to let you know.

julie777 commented 2 years ago

It works for me. test file:

seq_of_seqs:
  -
    - "a"
    - "b"
  -
    - 1
    - 2

output of strictyaml.load(test).data sent to pprint

{'seq_of_seqs': [['a', 'b'], ['1', '2']]}