https://github.com/soundvibe/jkob
Simple type-safe json builder
https://github.com/soundvibe/jkob
builder dsl json kotlin
Last synced: about 1 year ago
JSON representation
Simple type-safe json builder
- Host: GitHub
- URL: https://github.com/soundvibe/jkob
- Owner: soundvibe
- License: apache-2.0
- Created: 2017-06-16T08:03:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-07T20:31:01.000Z (about 8 years ago)
- Last Synced: 2025-04-01T15:11:50.719Z (about 1 year ago)
- Topics: builder, dsl, json, kotlin
- Language: Kotlin
- Size: 32.2 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jkob
[](https://travis-ci.org/soundvibe/jkob)
[](https://maven-badges.herokuapp.com/maven-central/net.soundvibe/jkob)
### Kotlin DSL for type-safe JSON building
##### An example of building JSON:
```kotlin
val json = json {
"id" to "value" //key->value pair
"name" to "foo"
"items" ["value1", "value2", "value3"] //array
for (i in 1..2) "item$i" to i //you can even use regular loops when building JSON
"numbers" [1, 2, 3]
"child" { //child object
"age" to 19
"isValid" to false
"isNull" to null
}
}
```
This JSON object representation can be converted to JSON string:
```kotlin
val jsonString = json.toString()
```
Output:
```javascript
{"id": "value", "name": "foo", "items": ["value1", "value2", "value3"], "item1": 1, "item2": 2, "numbers": [1, 2, 3], "child": {"age": 19, "isValid": false, "isNull": null}}
```
##### An example to retrieve elements from JSON:
```kotlin
val numbers = json["numbers"]?.toList()
println(numbers) //prints [1, 2, 3]
```
## Binaries
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cnet.soundvibe.reacto).
Example for Gradle:
```groovy
compile 'net.soundvibe:jkob:1.0.0'
```
and for Maven:
```xml
net.soundvibe
jkob
1.0.0
```
## Bugs and Feedback
For bugs, questions and discussions please use the [Github Issues](https://github.com/soundvibe/jkob/issues).
## LICENSE
Copyright 2017 Linas Naginionis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy to the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.