Skip to content

Instantly share code, notes, and snippets.

@propensive
Created November 17, 2014 08:41
Show Gist options
  • Save propensive/2893398a80a9ffdb04a4 to your computer and use it in GitHub Desktop.
Save propensive/2893398a80a9ffdb04a4 to your computer and use it in GitHub Desktop.
Compile-time JSON syntax checking in Rapture JSON
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": * }"""
^
@propensive
Copy link
Author

JSON literals will now get parsed at compile time.

@adriaanm
Copy link

Cool!

@rozza
Copy link

rozza commented Nov 17, 2014

Nice!

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