Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Last active June 3, 2021 06:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save darrelmiller/07fed784d2c20de9f5d3719977167181 to your computer and use it in GitHub Desktop.
Save darrelmiller/07fed784d2c20de9f5d3719977167181 to your computer and use it in GitHub Desktop.
Project.json comparison with XML equivalent
{
"authors": [
"Sam Saffron",
"Marc Gravell",
"Nick Craver"
],
"owners": [
"marc.gravell",
"nick.craver"
],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"summary": "A high performance Micro-ORM",
"description": "A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..",
"version": "1.50-beta9",
"title": "Dapper dot net",
"tags": [
"orm",
"sql",
"micro-orm"
],
"copyright": "2015 Stack Exchange, Inc.",
"dependencies": {},
"releaseNotes": "http://stackexchange.github.io/dapper-dot-net/",
"compilationOptions": {
"warningsAsErrors": true
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
}
},
"net45": {
"compilationOptions": {
"define": [
"ASYNC"
]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
}
},
"net451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
},
"compilationOptions": {
"define": [
"ASYNC"
]
}
},
"netstandard1.3": {
"compilationOptions": {
"define": [
"ASYNC",
"COREFX"
]
},
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24015",
"System.Data.SqlClient": "4.1.0-rc2-24015",
"System.Dynamic.Runtime": "4.0.11-rc2-24015",
"System.Reflection.Emit": "4.0.1-rc2-24015",
"System.Reflection.Emit.Lightweight": "4.0.1-rc2-24015",
"System.Xml.XmlDocument": "4.0.1-rc2-24015",
"System.Collections.NonGeneric": "4.0.1-rc2-24015",
"System.Reflection.TypeExtensions": "4.1.0-rc2-24015"
}
}
}
}
<project
authors="Sam Saffron, Marc Gravell, Nick Craver"
owners="marc.gravell, nick.craver"
projectUrl="https://github.com/StackExchange/dapper-dot-net"
licenseUrl="http://www.apache.org/licenses/LICENSE-2.0"
summary="A high performance Micro-ORM"
description="A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc.."
version= "1.50-beta9"
title= "Dapper dot net"
tags= "orm,sql,micro-orm"
copyright= "2015 Stack Exchange, Inc."
>
<releaseNotes>http://stackexchange.github.io/dapper-dot-net/</releaseNotes>
<compilationOptions warningsAsErrors="true"/>
<framework moniker="net40">
<assembly name="System.Data" version="4.0.0.0"/>
<assembly name="System.Xml" version="4.0.0.0"/>
<assembly name="System.Xml.Linq" version="4.0.0.0"/>
</framework>
<framework moniker="net45">
<compilationOptions define="ASYNC"/>
<assembly name="System.Data" version="4.0.0.0"/>
<assembly name="System.Xml" version="4.0.0.0"/>
<assembly name="System.Xml.Linq" version="4.0.0.0"/>
</framework>
<framework moniker="net451">
<compilationOptions define="ASYNC"/>
<assembly name="System.Data" version="4.0.0.0"/>
<assembly name="System.Xml" version="4.0.0.0"/>
<assembly name="System.Xml.Linq" version="4.0.0.0"/>
</framework>
<framework moniker="netstandard1.3">
<compilationOptions define="ASYNC,COREFX"/>
<dependency name="NETStandard.Library" version="1.5.0-rc2-24015"/>
<dependency name="System.Data.SqlClient" version="4.1.0-rc2-24015"/>
<dependency name="System.Dynamic.Runtime" version="4.0.11-rc2-24015"/>
<dependency name="System.Reflection.Emit" version="4.0.1-rc2-24015"/>
<dependency name="System.Reflection.Emit.Lightweight" version="4.0.1-rc2-24015"/>
<dependency name="System.Xml.XmlDocument" version="4.0.1-rc2-24015"/>
<dependency name="System.Collections.NonGeneric" version="4.0.1-rc2-24015"/>
<dependency name="System.Reflection.TypeExtensions" version="4.0.1-rc2-24015"/>
</framework>
</project>
@whitlockjc
Copy link

Here is are two example project.yaml, one created by an online JSON -> YAML converter and the other hand authored to be as small as possible (without impacting readability). The converted one is ~3% smaller than JSON and ~13% smaller than XML while the hand written one is ~7% smaller than JSON and ~17% smaller than XML. I'm not sure if this is useful but I see a number of structured document tools switching to, or at least allowing, YAML these days so I thought I'd bring it up. Not only that but from a consumption perspective, every language has a YAML parser these days.

Online Converted (overly cautious wrapping of strings)

---
  authors: 
    - "Sam Saffron"
    - "Marc Gravell"
    - "Nick Craver"
  owners: 
    - "marc.gravell"
    - "nick.craver"
  projectUrl: "https://github.com/StackExchange/dapper-dot-net"
  licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0"
  summary: "A high performance Micro-ORM"
  description: "A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc.."
  version: "1.50-beta9"
  title: "Dapper dot net"
  tags: 
    - "orm"
    - "sql"
    - "micro-orm"
  copyright: "2015 Stack Exchange, Inc."
  dependencies: {}
  releaseNotes: "http://stackexchange.github.io/dapper-dot-net/"
  compilationOptions: 
    warningsAsErrors: true
  frameworks: 
    net40: 
      frameworkAssemblies: 
        System.Data: "4.0.0.0"
        System.Xml: "4.0.0.0"
        System.Xml.Linq: "4.0.0.0"
    net45: 
      compilationOptions: 
        define: 
          - "ASYNC"
      frameworkAssemblies: 
        System.Data: "4.0.0.0"
        System.Xml: "4.0.0.0"
        System.Xml.Linq: "4.0.0.0"
    net451: 
      frameworkAssemblies: 
        System.Data: "4.0.0.0"
        System.Xml: "4.0.0.0"
        System.Xml.Linq: "4.0.0.0"
      compilationOptions: 
        define: 
          - "ASYNC"
    netstandard1.3: 
      compilationOptions: 
        define: 
          - "ASYNC"
          - "COREFX"
      dependencies: 
        NETStandard.Library: "1.5.0-rc2-24015"
        System.Data.SqlClient: "4.1.0-rc2-24015"
        System.Dynamic.Runtime: "4.0.11-rc2-24015"
        System.Reflection.Emit: "4.0.1-rc2-24015"
        System.Reflection.Emit.Lightweight: "4.0.1-rc2-24015"
        System.Xml.XmlDocument: "4.0.1-rc2-24015"
        System.Collections.NonGeneric: "4.0.1-rc2-24015"
        System.Reflection.TypeExtensions: "4.1.0-rc2-24015"

Hand Authored (removed unnecessary string wrapping)

---
  authors: 
    - Sam Saffron
    - Marc Gravell
    - Nick Craver
  owners: 
    - marc.gravell
    - nick.craver
  projectUrl: https://github.com/StackExchange/dapper-dot-net
  licenseUrl: http://www.apache.org/licenses/LICENSE-2.0
  summary: A high performance Micro-ORM
  description: A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..
  version: 1.50-beta9
  title: Dapper dot net
  tags: 
    - orm
    - sql
    - micro-orm
  copyright: 2015 Stack Exchange, Inc.
  dependencies: {}
  releaseNotes: http://stackexchange.github.io/dapper-dot-net/
  compilationOptions: 
    warningsAsErrors: true
  frameworks: 
    net40: 
      frameworkAssemblies: 
        System.Data: 4.0.0.0
        System.Xml: 4.0.0.0
        System.Xml.Linq: 4.0.0.0
    net45: 
      compilationOptions: 
        define: 
          - ASYNC
      frameworkAssemblies: 
        System.Data: 4.0.0.0
        System.Xml: 4.0.0.0
        System.Xml.Linq: 4.0.0.0
    net451: 
      frameworkAssemblies: 
        System.Data: 4.0.0.0
        System.Xml: 4.0.0.0
        System.Xml.Linq: 4.0.0.0
      compilationOptions: 
        define: 
          - ASYNC
    netstandard1.3: 
      compilationOptions: 
        define: 
          - ASYNC
          - COREFX
      dependencies: 
        NETStandard.Library: 1.5.0-rc2-24015
        System.Data.SqlClient: 4.1.0-rc2-24015
        System.Dynamic.Runtime: 4.0.11-rc2-24015
        System.Reflection.Emit: 4.0.1-rc2-24015
        System.Reflection.Emit.Lightweight: 4.0.1-rc2-24015
        System.Xml.XmlDocument: 4.0.1-rc2-24015
        System.Collections.NonGeneric: 4.0.1-rc2-24015
        System.Reflection.TypeExtensions: 4.1.0-rc2-24015

@sandorfr
Copy link

I love the yaml version

@tugberkugurlu
Copy link

JSON formatting is not quite good on this. That's one of the reasons why you see a big diff. See this: https://gist.github.com/tugberkugurlu/2ea39144ac9a4ec1c53153340704744a

I don't think neither JSON nor XML is the most optimum config file format. YAML is my preference. At the end of the day, this boils down to preference but I don't think that many of the eco systems use XML for config stuff. This should give a clue about its place.

@tugberkugurlu
Copy link

Great one @whitlockjc! YAML version is so much much better ✨

@pedroreys
Copy link

A toml version, that can be as terse and readable as the yaml version but doesn't have relevant whitespaces

authors = ["Sam Saffron", "Marc Gravell", "Nick Craver"]
owners = ["marc.gravell", "nick.craver"]

projectUrl = "https://github.com/StackExchange/dapper-dot-net"
licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
summary = "A high performance Micro-ORM"
description = "A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc.."
version = "1.50-beta9"
title = "Dapper dot net"
tags = ["orm", "sql", "micro-orm"]
copyright = "2015 Stack Exchange, Inc."
releaseNotes = "http://stackexchange.github.io/dapper-dot-net/"

[compilationOptions]
  warningsAsErrors = true

[dependencies]

[frameworks]
  [frameworks.net40]
    [frameworks.net40.frameworkAssemblies]
      "System.Data" = "4.0.0.0"
      "System.Xml" = "4.0.0.0"
      "System.Xml.Linq" = "4.0.0.0"

  [frameworks.net45]
    [frameworks.net45.compilationOptions]
      define = ["ASYNC"]

    [frameworks.net45.frameworkAssemblies]
      "System.Data" = "4.0.0.0"
      "System.Xml" = "4.0.0.0"
      "System.Xml.Linq" = "4.0.0.0"

  [frameworks.net451]
    [frameworks.net451.compilationOptions]
      define = ["ASYNC"]

    [frameworks.net451.frameworkAssemblies]
      "System.Data" = "4.0.0.0"
      "System.Xml" = "4.0.0.0"
      "System.Xml.Linq" = "4.0.0.0"

  [frameworks."netstandard1.3"]
    [frameworks."netstandard1.3".compilationOptions]
      define = ["ASYNC", "COREFX"]

    [frameworks."netstandard1.3".dependencies]    
      "NETStandard.Library" = "1.5.0-rc2-24015"
      "System.Collections.NonGeneric" = "4.0.1-rc2-24015"
      "System.Data.SqlClient" = "4.1.0-rc2-24015"
      "System.Dynamic.Runtime" = "4.0.11-rc2-24015"
      "System.Reflection.Emit" = "4.0.1-rc2-24015"
      "System.Reflection.Emit.Lightweight" = "4.0.1-rc2-24015"
      "System.Reflection.TypeExtensions" = "4.1.0-rc2-24015"
      "System.Xml.XmlDocument" = "4.0.1-rc2-24015"

@adamralph
Copy link

If handed editing is the aim, I've always said YAML or TOML beat XML or JSON. JSON is the worst of all.

@nbxx
Copy link

nbxx commented May 12, 2016

I like .ini file, just kidding :-)

@304NotModified
Copy link

<project
...
  summary="A high performance Micro-ORM"
    >
  <releaseNotes>http://stackexchange.github.io/dapper-dot-net/</releaseNotes>

Summary is an attribute, releasenotes is a element. These inconsistenties are bad and comes with the choice of XML. And then there is too much clutter (e.g. name= in the example), which makes the XML the worst of all.

The XML is now 15 bytes smaller than the JSON ;-)

Consistency and no noise is IMO more important.

@Mike-E-angelo
Copy link

This is a great discussion and examples! While format is important, what is more important to me is a strong backing model . I would rather see the project "schema" be a Project POCO that has a well-known/defined class structure which the file is based.

FWIW, I have created an issue around this here:
dotnet/project-system#37

And also there is an open discussion in MSBuild around formats here and project improvements here:
dotnet/msbuild#613

@malisancube
Copy link

I think XML is not bad. Parsing and tooling (for intellisense and stuff) should be easier to implement.

@douglasstarnes
Copy link

While XML is more verbose it has the advantage of being more descriptive. XML is also a better archival format. JSON is intended to be lightweight and ephemeral such as when passing small bits of data on a web service. If JSON is really a better format, then not only is Microsoft doing it wrong with .csproj and XAML but Apple is doing it wrong with Interface Builder and Google is doing it wrong with layout files. The W3C is even doing it wrong with HTML. At some point, archived files will need to be read by a human and XML is better suited for that. Just my two cents.

@asbjornu
Copy link

@whitlockjc, that hand edited YAML example almost brings me to tears of joy. If that was how project files in Visual Studio looked like, and the .sln file just disappeared (or turned into YAML as well), I'm sure my life would be lengthened by a few years. I at least know that currently, the horror of .sln, .csproj and MSBuild as a whole, is shortening my life expectancy due to heightened stress levels by a lot. I'm gnashing teeth just writing that last sentence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment