json-slim

Trims your JSON of unwanted adornments and attributes.

License

License

MIT
Categories

Categories

JSON Data
GroupId

GroupId

com.meetup
ArtifactId

ArtifactId

json-slim_2.11
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

json-slim
Trims your JSON of unwanted adornments and attributes.
Project URL

Project URL

https://github.com/meetup/json-slim/
Project Organization

Project Organization

com.meetup
Source Code Management

Source Code Management

http://github.com/meetup/json-slim/tree/master

Download json-slim_2.11

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.5
org.json4s : json4s-native_2.11 jar 3.2.11

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 2.2.1

Project Modules

There are no modules declared in this project.

json slim Coverage Status

make your JSON look good in those skinny jeans

Json slim trims your JSON of unwanted adornments and attributes.

Install

using sbt add the following to your build definition

resolvers += "softprops-bintray" at "http://dl.bintray.com/softprops/maven"

libraryDependencies += "com.meetup" % "json-slim" % "0.1.1"

or if you are using ls-sbt

just do

ls-install json-slim

usage

jsonslim provides a way to negotiate the presence ( or absence ) of properties within JSON-encoded objects. The vocabulary for doing is comprised to operations: only and omit. You can ask for only a set of attributes or, if you are feeling more conservative, you can ask to omit attributes.

paths

Target attributes of JSON-encoded object are referenced by simple . delimited strings which represent traversable paths to the attribute.

a.b.c will target the json field c of field b of field a. You may provide multiple paths for each operation. Only takes precedence over omit. If you ask for "only" a subset of fields, the "omit" will only apply to that subset.

example

Assume you have given the following JSON-encoded object

{
  "people": [{
    "name": "bill",
    "age": 30,
    "titles":["foo", "bar"]
  }]
}

Let's say you don't care for titles. Omit them with

jsonslim.Trim.omit("people.titles")(jsonStr) // Some({"people":[{"name":"bill","age":30}]})

Let's say you only want the names of people. Include only names with

jsonslim.Trim.only("people.name")(jsonStr) // Some({"people":[{"name":"bill"}]})

inputs

A Trim is an exported function that you can assign and apply to multiple inputs. Inputs for a Trim are defined as the following typeclass jsonslim.Src[T].

trait Src[T] {
  def apply(a: T): Option[JValue]
  def unapply(jv: JValue): T
}

A Src[T] needs a way to be lifted into an org.json4s.JValue, the intermediary format used to manipulate the JSON ast, and a way to go from an org.json4s.JValue back into type T. Since the lifting into a JValue may not be possible, failure may be represented as None. Src conversions for Strings and direct JVaules are provided. If you use an alternative type representation of JSON you will need to bring an implicit implementation of a Src into scope.

combining operations

You can also combine multiple attribute paths for each operation for a slim party

val trim = jsonslim.Trim.only("people.name", "foo.bar")
                        .omit("people.titles", "baz.boom")
val slim = jsonDocuments.map(trim(_)).flatten

Authors

License

Copyright 2013 Meetup inc

Licensed under MIT

com.meetup

Meetup

Versions

Version
0.1.1