Created
November 17, 2014 08:41
-
-
Save propensive/2893398a80a9ffdb04a4 to your computer and use it in GitHub Desktop.
Compile-time JSON syntax checking in Rapture JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import rapture.json._ | |
import rapture.json._ | |
scala> import jsonBackends.scalaJson._ | |
import jsonBackends.scalaJson._ | |
scala> json"{}" | |
res0: rapture.json.Json = {} | |
scala> json"""{ "foo"; "bar" }""" | |
<console>:14: error: Expected ':', but found ';' | |
json"""{ "foo"; "bar" }""" | |
^ | |
scala> json"""{ "foo": "bar")""" | |
<console>:14: error: Expected ',' or '}', but found ')' | |
json"""{ "foo": "bar")""" | |
^ | |
scala> json"""{ "foo": "bar", }""" | |
<console>:14: error: Expected '"', but found '}' | |
json"""{ "foo": "bar", }""" | |
^ | |
scala> json"""{ "foo": ${2 + 2} }""" | |
res5: rapture.json.Json = {"foo":4} | |
scala> json"""{ "foo": ${2 + 2}, "bar": * }""" | |
<console>:14: error: Expected new token, but found '*' | |
json"""{ "foo": ${2 + 2}, "bar": * }""" | |
^ | |
scala> json"""{ ${2 + 2}: "foo", "bar": * }""" | |
<console>:14: error: Expected '"' or '}', but found interpolated value | |
json"""{ ${2 + 2}: "foo", "bar": * }""" | |
^ |
Cool!
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSON literals will now get parsed at compile time.