O'Reilly logo

Modern Python Cookbook by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

There are a number of additional features in YAML that are not present in JSON:

  • The comments, which begin with # and continue to the end of the line. They can go almost anywhere. JSON doesn't tolerate comments.
  • The document start, which is indicated by the --- line at the start of a new document. This allows a YAML file to contain many individual objects. JSON is limited to a single document per file. The alternative to one document-per-file is somewhat a more complex parsing algorithm. YAML provides an explicit document separator and a very simple parsing interface.
  • The YAML file with two separate documents:
 
>>> import yaml >>> yaml_text = ''' ... --- ... id: 1 ... text: "Some Words." ... --- ... id: 2 ... text: "Different ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required