jsont-core

JSON template

License

License

MIT
Categories

Categories

JSON Data
GroupId

GroupId

com.github.foftware
ArtifactId

ArtifactId

jsont-core_2.12
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

jsont-core
JSON template
Project URL

Project URL

https://github.com/foftware/jsont
Project Organization

Project Organization

com.github.foftware
Source Code Management

Source Code Management

https://github.com/foftware/jsont

Download jsont-core_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.foftware/jsont-core_2.12/ -->
<dependency>
    <groupId>com.github.foftware</groupId>
    <artifactId>jsont-core_2.12</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.foftware/jsont-core_2.12/
implementation 'com.github.foftware:jsont-core_2.12:0.1.1'
// https://jarcasting.com/artifacts/com.github.foftware/jsont-core_2.12/
implementation ("com.github.foftware:jsont-core_2.12:0.1.1")
'com.github.foftware:jsont-core_2.12:jar:0.1.1'
<dependency org="com.github.foftware" name="jsont-core_2.12" rev="0.1.1">
  <artifact name="jsont-core_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.foftware', module='jsont-core_2.12', version='0.1.1')
)
libraryDependencies += "com.github.foftware" % "jsont-core_2.12" % "0.1.1"
[com.github.foftware/jsont-core_2.12 "0.1.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.typelevel : cats-core_2.12 jar 1.6.0
org.typelevel : cats-mtl-core_2.12 jar 0.5.0
io.circe : circe-core_2.12 jar 0.11.1

test (2)

Group / Artifact Type Version
org.typelevel : cats-testkit_2.12 jar 1.6.0
org.scalatest : scalatest_2.12 jar 3.0.5

Project Modules

There are no modules declared in this project.

Build Status codecov Gitter chat

Function-based Json templating language

Overview

jsont is a combinator based library for building Json validators.

Example

Most convenient way to describe your Json is to use one of the supplied string interpolators. You can use either the jsont:

import jsont.run
import jsont.literal._

val validator = jsont"""{
  "a": ${int(_ > 0)},
  "b": ${string(_.length % 5 == 0)},
  "c": [
    ${string(_.toUpperCase == "ABCD")},
    ${regex("""\d\d\d\d-\d\d-\d\d""".r)}
  ]
}"""

val validated = json"""{
  "a": 1,
  "b": "55555",
  "c": [
    "abcd",
    "2019-12-12"
  ]
}"""

run(validator, validated)
// Chain()

Or when used in tests, use scalatest's Matcher directly:

jsont"""{
  "a": ${int(_ > 0)},
  "b": ${string(_.length % 5 == 0)},
  "c": [
    ${string(_.toUpperCase == "ABCD")},
    ${regex("""\d\d\d\d-\d\d-\d\d""".r)}
  ]
}""" should matchJson """{
  "a": 1,
  "b": "55555",
  "c": [
    "abcd",
    "2019-12-12"
  ]
}"""

Getting started

Add the following to your build.sbt:

libraryDependencies += "com.github.foftware" % "jsont-core_2.12" % "0.1.1"
libraryDependencies += "com.github.foftware" % "jsont-literal_2.12" % "0.1.1"
libraryDependencies += "com.github.foftware" % "jsont-scalatest_2.12" % "0.1.1"
com.github.foftware

Foftware

Versions

Version
0.1.1