Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Why use JSON instead of YAML for Section definition? #1321

Closed
westonganger opened this issue May 29, 2019 · 12 comments
Closed

Why use JSON instead of YAML for Section definition? #1321

westonganger opened this issue May 29, 2019 · 12 comments
Labels
Milestone

Comments

@westonganger
Copy link
Contributor

westonganger commented May 29, 2019

Is there a reason why we are using JSON instead of YAML for the sections definition? This feels a little jarring, considering YAML is used for everything else.

@westonganger
Copy link
Contributor Author

I think the reason for JSON is that there is a better abstraction between Arrays and Hashes/Objects. Whereas in YAML it can be hard to differentiate what data type is what.

My main problem with JSON is having to use string keys gets me (ie. "label": "foobar"). Sometimes I accidentally write label: "foobar" and everything blows up and I go down a debugging rabbit hole.

Could we possibly also support quoteless keys in our JSON for simple developer ease. Ex.

{
  name: "Foobar",
  class: "my-class",
  settings: {
    label: "Title",
    id: "title",
    type: "string"
  }
}

This should be totally possible since we are completely in charge of parsing the JSON.

@westonganger
Copy link
Contributor Author

westonganger commented May 30, 2019

We can just use HJSON.

https://hjson.org/

JSON Add-Ons:

  • Trailing Commas
  • Comments (#, //, /* */)
  • Quoteless Keys
  • Quoteless String (meh but okay why not)
  • Write multiline strings with proper whitespace handling.

Thats all it does. Seems like the perfect solution to me.

Heres the ruby gem: https://github.com/hjson/hjson-rb

@westonganger
Copy link
Contributor Author

Could be just as simple as changing these three load statements methods in steam

https://github.com/locomotivecms/steam/search?q=MultiJson&unscoped_q=MultiJson

@westonganger
Copy link
Contributor Author

Maybe we could avoid this whole HJSON support if section definitions supported both YAML and JSON

@did
Copy link
Member

did commented Aug 3, 2019

@westonganger I like your suggestion! let me see if I can add it for v4.

@did did added this to the 4.0 milestone Aug 3, 2019
@did did added the feature label Aug 3, 2019
@did
Copy link
Member

did commented Aug 4, 2019

@westonganger @DonKoko @manuchap @thibaultrey
quick question, if we allow both json and yaml to describe a section, what would the default format be?

@westonganger
Copy link
Contributor Author

Everything else is YAML so I would say that should be the default.

@DonKoko
Copy link

DonKoko commented Aug 5, 2019

I really got used to the JSON but I agree with @westonganger that YAML would be more consistent with the rest.

@did
Copy link
Member

did commented Aug 8, 2019

@DonKoko @westonganger next steps:

  • modify the section generator in Wagon (YAML by default). This is great because I'm going to put comments in the header! (this is something I was missing before)
  • update the documentation about sections (replace JSON examples)

@did
Copy link
Member

did commented Aug 15, 2019

thanks again @westonganger. YAML is definitively the best choice. So simple to read and write compared to JSON. Besides, thanks to the Liquid HTML ST3 plugin, I've got the perfect code highlighting to read liquid pages.

@did did closed this as completed Aug 15, 2019
@DonKoko
Copy link

DonKoko commented Aug 23, 2019

I think its great that we have both options. I have to disagree that YAML is better when it comes to complex data structures, as for a person who never user YAML, its super confusing how do you manage arrays and objects, and with JSON it follows the conventions that we all know and love, arrays with [] and objects with {}. This can make it very confusing to debug, especially considering how dependent it is on indentation. I personally would not use it, but again, i think its a good option to have.

@manuchap
Copy link
Contributor

manuchap commented Aug 23, 2019

I'm like 50/50 on this. Maybe 51/49 towards json since js devs and apis use it a lot and it fits well with wagon sync and mongo which I hope will never be replaced with potgresql 😅
(also wish it could be the same with pages headers)
Off subject but I feel the same about haml which should definitely be devs favorite language once they try it for real.
Actually it'd be nice to have the option in wagon to go full json or full yaml 😉

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants