Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Comparison of data formats supported #5

Closed
chenyong opened this issue Jan 10, 2020 · 1 comment
Closed

Comparison of data formats supported #5

chenyong opened this issue Jan 10, 2020 · 1 comment

Comments

@chenyong
Copy link
Contributor

chenyong commented Jan 10, 2020

Currently serve-json supports 4 formats of data files: edn json cirru cson.

  • .cirru - Cirru EDN

Cirru is my favorite one. It looks clean and has 1016 chars(including spaces).

{}
  :port 7800
  :routes $ []
    {}
      :path |home
      :get $ {} (:type :file) (:file |home.json)
    {}
      :path |plants/:plant-id
      :get $ {} (:type :file) (:file |plant-default.json)
      :post $ {} (:type :file) (:file |ok.json)
      :next $ []
        {}
          :path |overview
          :get $ {} (:type :file) (:file |overview.json)
        {}
          :path |materials/:material-id
          :get $ {} (:type :file) (:file |materials.json)
          :next $ []
            {}
              :path |events
              :get $ {} (:type :file) (:file |events.json)
              :delete $ {} (:code 202) (:type :file) (:file |ok.json)
    {}
      :path |notifications/me
      :next $ []
        {}
          :path |messages
          :get $ {} (:type :file) (:file |messages.json)
        {}
          :path |messages:latestUnread
          :get $ {} (:type :file) (:file |unread-mesages.json)
    {}
      :path |user/settings/preferences
      :put $ {} (:type :file) (:file |ok.json)
  • EDN

EDN is the default data used in ClojureScript. It has 1053 chars and looks really compact.

But people feel bored in getting colons aligned to the previous ones.

{:port 7800,
 :routes [{:path "home", :get {:type :file, :file "home.json"}}
          {:path "plants/:plant-id",
           :get {:type :file, :file "plant-default.json"},
           :post {:type :file, :file "ok.json"},
           :next [{:path "overview",
                   :get {:type :file, :file "overview.json"}}
                  {:path "materials/:material-id",
                   :get {:type :file, :file "materials.json"},
                   :next [{:path "events",
                           :get {:type :file, :file "events.json"},
                           :delete {:code 202,
                                    :type :file,
                                    :file "ok.json"}}]}]}
          {:path "notifications/me",
           :next [{:path "messages",
                   :get {:type :file, :file "messages.json"}}
                  {:path "messages:latestUnread",
                   :get {:type :file, :file "unread-mesages.json"}}]}
          {:path "user/settings/preferences",
           :put {:type :file, :file "ok.json"}}]}

So there another EDN(Flavored EDN) indented like JSON, it's also neat, but containing more lines since { and } are used:

{
  :port 7800
  :routes [
    {
      :path "home"
      :get {:type :file, :file "home.json"}
    }
    {
      :path "plants/:plant-id"
      :get {:type :file, :file "plant-default.json"}
      :post {:type :file, :file "ok.json"}
      :next [
        {
          :path "overview"
          :get {:type :file, :file "overview.json"}
        }
        {
          :path "materials/:material-id"
          :get {:type :file, :file "materials.json"}
          :next [
            {
              :path "events"
              :get {:type :file, :file "events.json"}
              :delete {:code 202, :type :file, :file "ok.json"}
            }
          ]
        }
      ]
    }
    {
      :path "notifications/me"
      :next [
        {
          :path "messages"
          :get {:type :file, :file "messages.json"}
        }
        {
          :path "messages:latestUnread"
          :get {:type :file, :file "unread-mesages.json"}
        }
      ]
    }
    {
      :path "user/settings/preferences"
      :put {:type :file, :file "ok.json"}
    }
  ]
}
  • JSON

Then comes JSON, it's like Flavored EDN but with more quotes and commas, not good for writing:

{
  "port": 7800,
  "routes": [
    {
      "path": "home",
      "get": {
        "type": "file",
        "file": "home.json"
      }
    },
    {
      "path": "plants/:plant-id",
      "get": {
        "type": "file",
        "file": "plant-default.json"
      },
      "post": {
        "type": "file",
        "file": "ok.json"
      },
      "next": [
        {
          "path": "overview",
          "get": {
            "type": "file",
            "file": "overview.json"
          }
        },
        {
          "path": "materials/:material-id",
          "get": {
            "type": "file",
            "file": "materials.json"
          },
          "next": [
            {
              "path": "events",
              "get": {
                "type": "file",
                "file": "events.json"
              },
              "delete": {
                "code": 202,
                "type": "file",
                "file": "ok.json"
              }
            }
          ]
        }
      ]
    },
    {
      "path": "notifications/me",
      "next": [
        {
          "path": "messages",
          "get": {
            "type": "file",
            "file": "messages.json"
          }
        },
        {
          "path": "messages:latestUnread",
          "get": {
            "type": "file",
            "file": "unread-mesages.json"
          }
        }
      ]
    },
    {
      "path": "user/settings/preferences",
      "put": {
        "type": "file",
        "file": "ok.json"
      }
    }
  ]
}
  • CSON(CoffeeScript JSON)

CSON is much more neat than any of above. It's in 783 chars, really sharp.

port: 7800
routes: [
  path: 'home'
  get: type: 'file', file: 'home.json'
,
  path: 'plants/:plant-id'
  get:
    type: 'file'
    file: 'plant-default.json'
  post: type: 'file', file: 'ok.json'
  next: [
    path: 'overview'
    get: type: 'file', file: 'overview.json'
  ,
    path: 'materials/:material-id'
    get: type: 'file', file: 'materials.json'
    next: [
        path: 'events'
        get: type: 'file', file: 'events.json'
        delete: code: 202, type: 'file', file: 'ok.json'
    ]
  ]
,
  path: 'notifications/me'
  next: [
    path: 'messages'
    get: type: 'file', file: 'messages.json'
  ,
    path: 'messages:latestUnread'
    get: type: 'file', file: 'unread-mesages.json'
  ]
,
  path: 'user/settings/preferences'
  put: type: 'file', file: 'ok.json'
]

Personally I like Cirru since it contains no long [ ... ] or { ... }, which is quite fluent for handwriting, no need to balance brackets.

Flavored EDN would be just fine for people familiar with JSON but want fewer chars. CSON would be great for indentation enthusiasts.

@chenyong
Copy link
Contributor Author

chenyong commented Jan 13, 2020

Who's the boss! 518 chars:

---
port: 7800
routes:
- path: home
  get:
    type: file
    file: home.json
- path: plants/:plant-id
  get:
    type: file
    file: plant-default.json
  post:
    type: file
    file: ok.json
  next:
  - path: overview
    get:
      type: file
      file: overview.json
  - path: materials/:material-id
    get:
      type: file
      file: materials.json
    next:
    - path: events
      get:
        type: file
        file: events.json
      delete:
        code: 202
        type: file
        file: ok.json

Just added support.

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

No branches or pull requests

1 participant