Skip to content
This repository has been archived by the owner. It is now read-only.
[ABANDONED] A small Scala library for using JSON-based configuration files.
Branch: development
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


You probably don't need another data format, right?

Fig is a very small Scala library which makes it easy to read data out of JSON-based configuration files, with full support for Javascript-style comments. (We're not barbarians here.)


  • Scala 2.8.1 or 2.9.0-1 or 2.9.1
  • Jerkson 0.4.1


  • enough structure for most purposes
  • fairly human-readable
  • very well supported
  • easy to use with configuration management systems like Chef or Puppet

How To Use

First, specify Fig as a dependency:



Second, write your config file:

    /* Config allows you to use C-style comments.
     * This, for example, is a block comment.
    "parent": { // Comments can terminate a line, too.
        "child": {
            "url": "",
            // We don't care about comments inside string literals.
            "splody-string": "An-a one an-a two an-a // /*wah*/ YAY",
            "count": 100,
            "names": ["One", "Two", "Three"],
            "mapped": {
                "1": 1,
                "2": 2,
                "3": 3
            "doubly-mapped": {
                "1": [1, 2, 3],
                "2": [2, 3, 4],
                "3": [3, 4, 5]

Third, load your config file:

import com.codahale.fig.Configuration

val config = new Configuration("myapp/config.json")

You can also create a new Configuration instance from a Source or an InputStream.

Fourth, read values from it:

// Load a value directly.
val port = config("http.port").as[Int]

// Load a value as an option.
val uri = config("http.uri").asOption[Int]

// Load a value or a default value.
var server = config("http.server").or("Fig-Powered")

// Load a list of values.
val numbers = config("http.numbers").asList[Int]

// Or a map of values (key are required to be strings)
val properties = config("http.resource").asMap[String]

// Hell, even load a case class.
case class ResourceConfig(name: String, uri: String)
val resource = config("http.resource").as[ResourceConfig]

// Defy type erasure for lists!
val numbers = config("http.more-numbers").asMap[List[Int]]


Copyright (c) 2010-2011 Coda Hale

with contributions from

  • Bryan J Swift

Published under The MIT License, see LICENSE

You can’t perform that action at this time.