News for hackers. Stuff that matters.
Re:JSON vs. YAML – try it yourself by nperez on Tuesday April 07, 2015 @02:33AM (#9332305)
This is valid JSON in the same LOC: http://i.imgur.com/gv79uNM.png

It just seems like YAML is making things more implicit. I like explicitness. Not against YAML, but it's no holy grail in my mind.

I'm more experienced with JSON than YAML and could be swayed on this, but so far I'm not. They seem like two roughly equal ways to do the same thing.

This seems oddly similar to the nit-picky problems people have when learning Python from a C-like background and being annoyed that semicolons and flexible indentation aren't the norm. When I spend months working on JS code, looking at Python slightly annoys me, and vice-versa, so I think I get it. I just don't think it's an important, game-changing thing.

I'll be learning about Ansible soon, so I'll have to also learn YAML syntax. I guess I'll have a more educated view once I've gotten deep into that.

Re:JSON vs. YAML – try it yourself by simcop2387 on Tuesday April 07, 2015 @02:57AM (#9332367)
It may not look like it but it's just as explicit in YAML as it is in JSON. In fact JSON is valid YAML even: http://viewsourcecode.org/why/redhanded/inspect/yamlIsJson.h...
Re:JSON vs. YAML – try it yourself by AnkhMorporkian on Tuesday April 07, 2015 @02:58AM (#9332371)
YAML has a couple big advantages (in the proper situations) over JSON. Self-referencing, complex datatypes, and (my personal favorite) embedded block literals. I've, perhaps unwisely, embedded entire webpages a single indentation level after a variable and retained all of its formatting.

I'm no YAML zealot though, I do use JSON most of the time, but in the past couple years I've started writing most of my config files in YAML where I have the opportunity.

Re:JSON vs. YAML – try it yourself by hliyan on Tuesday April 07, 2015 @03:29AM (#9332458)
We recently moved much of our application's schema definitions and configurations out of code/JSON and into YAML files (we generate JSON during the build process in placess where it is necessary). A pleasant side effect was that the YAML file set began to double as basic documentation.

e.g.

    name: user
    plural: users
    label: User
    ...
    primary_key: uid
    display_key: full_name
    unique_keys:
        - username
        - uid
    client:
        storage:
            type: IndexedDB
    ...
        actions:
            create:
                label: Save
                permission: create_user
    ...
    server:
        storage:
            type: mysql
    ...
        api:
            create_user:
                url: /users
                method: post
    fields:
        username:
            name: username
            label: Username
            type: string
            length: 20
            required: true
            editable: false
Re:JSON vs. YAML – try it yourself by nperez on Tuesday April 07, 2015 @05:01AM (#9332697)
This is very interesting.

So is this the equivalent of multiple JSON documents? I'm looking at:

http://yaml.org/spec/1.1/#id857577 and http://yaml.org/spec/1.1/#stream/information%20model

I'm actually having a hard time, even with some google-fu, finding information about how this might be used. YAML->json parsers have failed to handle docs with a '...' separating parts of a document so far. Would this triple-dot structure be used to create multiple JS objects? How would I find more information about how this might be used in practice?

I have a feeling this would be easier to figure out if I just went and played around with it in practice, but it also seems like something that could be documented in more beginner-friendly terms.

I'll probably be kicking myself once I figure it out, but I also only have a cursory understanding of how streams work. Maybe this is an opportunity to fix that. Once I figure it out, I'll respond to this if nobody else has.

Re:JSON vs. YAML – try it yourself by quesera on Tuesday April 07, 2015 @08:23AM (#9333416)
I think the GP was using '...' as a standard "stuff removed for brevity" ellipsis.

However, since you asked:

In a YAML document, there is an implicit top-level object, either a hash/dict/associative array or a list/array depending on your formatting.

The '...' separates streams, or top-level objects, within a single file or IO stream.

YAML parsers generally stop when they hit the separator, even in languages that can do multiple assignment. If your IO stream behaves like a file handle, you can read it repeatedly into different variables until EOF.

Multiple streams in a YAML document are fairly uncommon. I think most people don't know they exist, but I appreciate the flexibility and use it whenever it makes sense.

Re:JSON vs. YAML – try it yourself by hliyan on Tuesday April 07, 2015 @02:10PM (#9335900)
Actually the '...' is for parts I've omitted for brevity.