jsonf

JsonF is a straight forward way to fetch values from JSON

Лицензия

Лицензия

MIT
Категории

Категории

JSON Данные
Группа

Группа

com.github.princesslana
Идентификатор

Идентификатор

jsonf
Последняя версия

Последняя версия

0.2.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

jsonf
JsonF is a straight forward way to fetch values from JSON
Ссылка на сайт

Ссылка на сайт

https://github.com/princesslana/jsonf
Система контроля версий

Система контроля версий

https://github.com/princesslana/jsonf

Скачать jsonf

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.apache.logging.log4j : log4j-api jar 2.14.0

provided (4)

Идентификатор библиотеки Тип Версия
com.google.code.gson : gson jar 2.8.6
com.fasterxml.jackson.core : jackson-core jar 2.12.0
com.fasterxml.jackson.core : jackson-databind jar 2.12.0
com.eclipsesource.minimal-json : minimal-json jar 0.9.5

test (3)

Идентификатор библиотеки Тип Версия
org.assertj : assertj-core jar 3.18.1
net.jqwik : jqwik-api jar 1.3.10
net.jqwik : jqwik jar 1.3.10

Модули Проекта

Данный проект не имеет модулей.

JsonF

Maven Central javadoc Build Maintainability Rating Coverage Discord

JsonF is a straight forward way to fetch values from JSON.

It does not implement JSON parsing itself, but instead presents a consistent and straight forward API on top of whichver JSON library you are already using.

Installing

JsonF is distributed via maven central.

To use with maven:

  <dependency>
    <groupId>com.github.princesslana</groupId>
    <artifactId>jsonf</artifactId>
    <version>LASTEST_VERSION</version>
  </dependency>

With gradle:

  implementation("com.github.princesslana:jsonf:LATEST_VERSION")

You will also need a supported JSON library on your classpath. JsonF currently supports:

Examples

Consider the following json object:

{
  "id": 123,
  "name": {
    "title": "Princess"
    "given_name": "Lana"
  },
  "interests": [ "Java", "Purple" ]
}

To create a JsonF instance JSON can be parsed directly from a String:

  JsonF jsonf = JsonF.parse(json);

It may also be created from an instance of a JSON object created via a supported library. For exampe a JsonObject from GSON or Jackson.

  JsonF jsonf = JsonF.from(jsonObj);

The get methods can be used to navigate through the JSON structure, while the asXxx methods (e.g., asString) fetch values. All asXxx methods return Optionals. Optional.empty will be returned if navigation was to a non-existent element, or if the element is not of the matching data type.

For the document given above:

  jsonf.get("id").asLong();                  // Optional.of(123)
  jsonf.get("id").asString();                // Optional.empty()

  jsonf.get("name").get("title").asString(); // Optional.of("Princess")
  jsonf.get("interests").get(0).asString();  // Optional.of("Java")

  jsonf.get("foo").asString();               // Optional.empty()

A varags variant of get exists as a convenince for successive get calls:

  jsonf.get("name", "given_name").asString(); // Optional.of("Lana")
  jsonf.get("interests", 1).asString();       // Optional.of("Purple")
  jsonf.get("name", "surname").asString();    // Optional.empty()

JsonF is able to iterate over JSON arrays. If the element navigated to is not an array then zero iterations will be performed. There is also stream and flatMap to assist with collecting data from a JSON array.

  // Will output "Java" and "Purple"
  for (var s : json.get("interests")) {
    System.out.println(s); 
  }

  // Stream version of the above
  json.get("interests").stream().forEach(s -> System.out.println(s));

  // No output, no error. No iterations as not an array
  for (var s : json.get("name")) {
    System.out.println(s);
  }

Contact

Reach out to the Discord Projects Hub on Discord and look for the jsonf channel.

Development

To run the junit tests:

$ mvn test

To run the code formatter:

$ mvn spotless:apply

To run the full set of verifications (including style checks):

$ mvn verify
com.github.princesslana

Версии библиотеки

Версия
0.2.1
0.2.0
0.1.1
0.1.0
0.0.1