All Projects → jvican → Dijon

jvican / Dijon

A Dynamically Typed Scala Json Library

Programming Languages

scala
5932 projects

Labels

Projects that are alternatives of or similar to Dijon

Jsonwatch
Track changes in JSON data from the command line
Stars: ✭ 130 (-6.47%)
Mutual labels:  json
Aping
angular module to get and display data by adding html-attributes
Stars: ✭ 135 (-2.88%)
Mutual labels:  json
Dhooks
A simple python Discord webhook API wrapper
Stars: ✭ 136 (-2.16%)
Mutual labels:  json
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (-5.04%)
Mutual labels:  json
D3r
d3.js helpers for R
Stars: ✭ 133 (-4.32%)
Mutual labels:  json
Mjson
C/C++ JSON parser, emitter, JSON-RPC engine for embedded systems
Stars: ✭ 136 (-2.16%)
Mutual labels:  json
Gojsonq
A simple Go package to Query over JSON/YAML/XML/CSV Data
Stars: ✭ 1,790 (+1187.77%)
Mutual labels:  json
Libvirt Hook Qemu
Libvirt hook for setting up iptables port-forwarding rules when using NAT-ed networking.
Stars: ✭ 137 (-1.44%)
Mutual labels:  json
Aws Lambda Scala
Writing AWS Lambdas in Scala
Stars: ✭ 135 (-2.88%)
Mutual labels:  json
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+1200.72%)
Mutual labels:  json
Httpexpect
End-to-end HTTP and REST API testing for Go.
Stars: ✭ 1,821 (+1210.07%)
Mutual labels:  json
Gloss
[Deprecated] A shiny JSON parsing library in Swift ✨ Loved by many from 2015-2021
Stars: ✭ 1,648 (+1085.61%)
Mutual labels:  json
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-2.16%)
Mutual labels:  json
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (-5.04%)
Mutual labels:  json
Fblog
Small command-line JSON Log viewer
Stars: ✭ 137 (-1.44%)
Mutual labels:  json
Pyjson tricks
Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Stars: ✭ 131 (-5.76%)
Mutual labels:  json
Elasticsearch Dataformat
Excel/CSV/BulkJSON downloads on Elasticsearch.
Stars: ✭ 135 (-2.88%)
Mutual labels:  json
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+1234.53%)
Mutual labels:  json
Kafka Connect Mongodb
**Unofficial / Community** Kafka Connect MongoDB Sink Connector - Find the official MongoDB Kafka Connector here: https://www.mongodb.com/kafka-connector
Stars: ✭ 137 (-1.44%)
Mutual labels:  json
Reconfigure
Config-file-to-Python mapping library (ORM).
Stars: ✭ 136 (-2.16%)
Mutual labels:  json

Continuous Integration

dijon - Dynamic JSON in Scala

val (name, age) = ("Tigri", 7)
val cat = json"""
  {
    "name": "$name",
    "age": $age,
    "hobbies": ["eating", "purring"],
    "is cat": true
  }
"""
assert(cat.name == name)                         // dynamic type
assert(cat.age == age)
val Some(catAge: Int) = cat.age.asInt
assert(catAge == age)
assert(cat.age.asBoolean == None)

val catMap = cat.toMap                           // view as a hashmap
assert(catMap.toMap.keysIterator.toSeq == Seq("name", "age", "hobbies", "is cat"))

assert(cat.hobbies(1) == "purring") // array access
assert(cat.hobbies(100) == None)    // missing element
assert(cat.`is cat` == true)        // keys with spaces/symbols/scala-keywords need to be escaped with ticks
assert(cat.email == None)           // missing key

val vet = `{}`                      // create empty json object
vet.name = "Dr. Kitty Specialist"   // set attributes in json object
vet.phones = `[]`                   // create empty json array
val phone = "(650) 493-4233"
vet.phones(2) = phone               // set the 3rd item in array to this phone
assert(vet.phones == mutable.Seq(None, None, phone))  // first 2 entries None

vet.address = `{}`
vet.address.name = "Animal Hospital"
vet.address.city = "Palo Alto"
vet.address.zip = 94306
assert(vet.address == mutable.Map[String, SomeJson]("name" -> "Animal Hospital", "city" -> "Palo Alto", "zip" -> 94306))

cat.vet = vet                            // set the cat.vet to be the vet json object we created above
assert(cat.vet.phones(2) == phone)
assert(cat.vet.address.zip == 94306)     // json deep access

println(cat) // {"name":"Tigri","age":7,"hobbies":["eating","purring"],"is cat":true,"vet":{"name":"Dr. Kitty Specialist","phones":[null,null,"(650) 493-4233"],"address":{"name":"Animal Hospital","city":"Palo Alto","zip":94306}}}

assert(cat == parse(cat.toString))   // round-trip test

var basicCat = cat -- "vet"                                  // remove 1 key
basicCat = basicCat -- ("hobbies", "is cat", "paws")         // remove multiple keys ("paws" is not in cat)
assert(basicCat == json"""{ "name": "Tigri", "age": 7}""")   // after dropping some keys above
  • Simple deep-merging:
val scala = json"""
{
  "name": "scala",
  "version": "2.13.2",
  "features": {
    "functional": true,
    "awesome": true
  }
}
"""

val java = json"""
{
  "name": "java",
  "features": {
    "functional": [0, 0],
    "terrible": true
  },
  "bugs": 213
}
"""

val scalaCopy = scala.deepCopy
val javaCopy = java.deepCopy

assert((scala ++ java) == json"""{"name":"java","version":"2.13.2","features":{"functional":[0,0],"terrible":true,"awesome":true},"bugs":213}""")
assert((java ++ scala) == json"""{"name":"scala","version":"2.13.2","features":{"functional": true,"terrible":true,"awesome":true},"bugs":213}""")

assert(scala == scalaCopy)       // original json objects stay untouched after merging
assert(java == javaCopy)
val json = `{}`
json.aString = "hi"                        // compiles
json.aBoolean = true                       // compiles
json.anInt = 23                            // compiles
//json.somethingElse = Option("hi")       // does not compile
val Some(i: Int) = json.anInt.asInt
assert(i == 23)
assert(json.aBoolean.asInt == None)
  • obj() and arr() constructor functions for building up complex JSON values with less overhead:
val rick = obj(
  "name" -> name,
  "age" -> age,
  "class" -> "human",
  "weight" -> 175.1,
  "is online" -> true,
  "contact" -> obj(
    "emails" -> arr(email1, email2),
    "phone" -> obj(
      "home" -> "817-xxx-xxx",
      "work" -> "650-xxx-xxx"
    )
  ),
  "hobbies" -> arr(
    "eating",
    obj(
      "games" -> obj(
        "chess" -> true,
        "football" -> false
      )
    ),
    arr("coding", arr("python", "scala")),
    None
  ),
  "toMap" -> arr(23, 345, true),
  "apply" -> 42
)

See the spec for more examples.

Also, for the dijon.codec an additional functionality is available when using jsoniter-scala-core, like:

  • parsing/serialization from/to byte arrays, byte buffers, and input/output streams
  • parsing of streamed JSON values (concatenated or delimited by whitespace characters) and JSON arrays from input streams using callbacks without the need of holding a whole input in the memory
  • use a custom configuration for parsing and serializing

See jsoniter-scala-core spec for more details and code samples.

Usage

  1. Add the following to your build.sbt:
libraryDependency += "me.vican.jorge" %% "dijon" % "0.4.0"
  1. Turn on support of dynamic types by adding import clause:
import scala.language.dynamics._

or by setting the scala compiler option:

scalacOptions += "-language:dynamics"
  1. Add import of the package object of dijon for the main functionality:
import dijon._
  1. Optionally, add import of package object of jsoniter-scala-core for extended json functionality:
import com.github.plokhotnyuk.jsoniter_scala.core._

TODO

  • BigInt support
  • Circular references checker
  • YAML interpolator
  • Macro for type inference to induce compile-time errors where possible
  • JSON string interpolator fills in braces, quotes and commas etc
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].