Ruby on Rails Advent Calendar 2017 19日目の記事です。 RailsでAPI開発するときのJSONレスポンスの生成方法についてまとめてみました。 JSONレスポンスの生成方法についてRailsのHTTPレスポンスをJSONで生成する方法は以下の2つに分類されますrenderメソッドにjson引数を指定する(モデル方式)templateハンドラでレンダリングする(ビュー方式)ライブラリでいうとactive_model_serializersは1のモデル方式、jbuilderやjbは2のビュー方式になります。モデル方式はrenderメソッドにjson引数が指定されているとActionController::Renderers#_render_with_renderer_json が呼び出され、指定したオブジェクトのto_jsonメソッドが呼び出されることでシリ
はじめに この記事は、Simple-JSONの作者であるJustin Wooさん(@kimagure)の記事を翻訳したものです。 twitterでこのようなことを書いてくださっていたので、たまたま反応した @oreshinya が翻訳することになりました。 JSONのような何らかのテキストデータを、プログラムで利用できるデータ型にパースすることは、私たちが使用している言語のほとんどについて行う必要があることです。いくつかの言語では、パーサーを書く方法を習得する必要がありますが、PureScriptでは、Simple-JSONを使うことにより、機械的にパースすることができます。私は、PureScript 0.11.6でRowToList機能がリリースされた時にこのライブラリを書きました。このライブラリは型シノニムを書くだけで使用できます。 プロジェクトのセットアップ このライブラリを使うプロ
JSON Compilation Database Format Specification¶ This document describes a format for specifying how to replay single compilations independently of the build system. Background¶ Tools based on the C++ Abstract Syntax Tree need full information how to parse a translation unit. Usually this information is implicitly available in the build system, but running tools as part of the build system is not n
We — Manton Reece and Brent Simmons — have noticed that JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. JSON is simpler to read and write, and it’s less prone to bugs. So we developed JSON Feed, a format similar to RSS and Atom but in JSON. It reflects the lessons learned from our years of work reading and publishing feeds. See the
The OpenAPI Specification is a community-driven open specification within the OpenAPI Initiative, a Linux Foundation Collaborative Project. The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs. This allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, addit
JSONStore is a Go-library for a simple thread-safe in-memory JSON key-store with persistent backend. It's made for those times where you don't need a RDBMS like MySQL, or a NoSQL like MongoDB - basically when you just need a simple keystore. A really simple keystore. JSONStore is used in those times you don't need a distributed keystore like etcd, or a remote keystore Redis or a local keystore lik
この記事は Vim 8.0 Advent Calendar の 4 日目の記事です。 チャンネルやジョブが追加されたのに合わせて、外部と JSON でのやり取りを行うことを想定して、JSON サポートが追加されました。 エンコード/デコードする json_encode() と json_decode() を使うことで、Vim の内部データと JSON 文字列を相互に変換できます。 let obj = {'users': [{'name': 'thinca', 'lang': 'vim'}]} let json = json_encode(obj) echo json " => {"users":[{"lang":"vim","name":"thinca"}]} echo json_decode(json) " => {'users': [{'lang': 'vim', 'name': 't
この記事は Vim 8.0 Advent Calendar の 2 日目の記事です。 Vim 8.0 では、外部リソースとのやりとりを行う機能としてチャンネルが追加されました。 本記事では、チャンネルの基本的な使い方として、ソケット通信を行う方法について簡単に説明します。 詳細については Vim 付属の help を参照してください。 チャンネルを使う この例では、ローカルホストの HTTP サーバに対して ch_sendraw() 関数を使ってリクエストを送り、結果をハンドラで受け取って表示しています。 " リモートからのレスポンスがあった際に呼ばれるハンドラ関数を定義します function! s:handle(ch, msg) abort " レスポンスを表示します。実際にはタイミング次第ではレスポンスが分割される可能性もあり得ます echo a:msg " ch_close() 関
NOTE: rq is in very low maintenance mode as my day job is taking up a lot of my time. I will try my best to merge pull requests but will not drive active development of this crate. NOTE: rq no longer ships with query support and a Javascript engine is not included; instead, it focuses exclusively on format transformation. You can still pipe into a runtime like node.js if you need Javascript evalua
きっかけは、昨夜の思いつきでした。 今日ふと思ったこと: JSONって、そもそもカンマ要らないんじゃね? { "Foo" : "BAR" "BAR": "Baz" "Hoge" : { "name" : "Hoge" } } 特に曖昧性なくパーズできるように思える。配列も同じく。— Kota Mizushima (@kmizu) 2016年11月6日 JSONでも以前から、末尾のカンマを許すようにしてほしいとかそういう要望があったと記憶していましたが、そもそもカンマを要らなくすれば解決では?というのが動機です。 NSONは次のような特徴を持っています。 オブジェクトの属性を区切るカンマが必要ない 配列の要素を区切るカンマが必要ない 属性のキーとして、文字列リテラルの他に通常の識別子が使える JSONの完全上位互換である まず最初の点についてですが、たとえば、 { "x": 1 "y": 2
(【追記】コメントにあるようにgc373さんのご協力で、問題のデータはJSONとして修正されています。) データは大切です。優れたデータは社会によい価値を提供するでしょう。優れたデータというのは、価値の高い情報を持っているだけでなく、それが扱いやすいということも大切でしょう。扱いやすいというのは、データに簡単にアクセスでき、そのデータを容易に読み込めるということでしょう。特別なソフトウェア用の形式であったり、余計なものが書かれていて読む前に人間が読まないといけないというのは扱いづらいと言えるでしょう。SHIFT_JISなのも困りものです。 とはいえ、まずはデータがあって初めて何かができるわけで、オープンデータとして、政府がデータを公開し始めているのは評価すべきことのはずです。しかし、どのような状態のデータを公開すると良いのかについてはノウハウが不十分におもわれます。 さて、http://w
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く