https://github.com/objectionary/eo-json
https://github.com/objectionary/eo-json
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/objectionary/eo-json
- Owner: objectionary
- License: mit
- Created: 2022-04-17T19:18:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-02-28T09:54:52.000Z (11 months ago)
- Last Synced: 2025-02-28T16:44:08.724Z (11 months ago)
- Size: 133 KB
- Stars: 6
- Watchers: 4
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/objectionary/eo-hamcrest)
[](https://www.jetbrains.com/idea/)
[](https://maven-badges.herokuapp.com/maven-central/org.eolang/eo-hamcrest)
[](https://github.com/objectionary/eo-hamcrest/actions/workflows/mvn.yml)
[](https://codecov.io/gh/cqfn/eo)
[](https://github.com/Graur/eo-tests/blob/master/LICENSE.txt)
[](https://codeclimate.com/github/objectionary/eo-hamcrest/maintainability)
[](https://hitsofcode.com/github/graur/eo-hamcrest/view)


[EOLANG](https://www.eolang.org) objects for JSON parsing.
The main idea is that everything is a json
This is how to create json object
```
+alias org.eolang.fs.json
# The first way is to call the json method 'of-...'
# It creates empty object/array or wrapped int/string
json.of-object > x1
json.of-array > x2
json.of-int 42 > x3
json.of-string "some string" > x4
# The second way is to parse the json text
json.parse "{age: 21, name: \"John\"}" > x5
```
JSON string for the following examples (the name of the string is **data**)
```
{
"id": 1,
"essence": "shelf",
"books": [
{
"title": "Winnie the Pooh",
"author": "Alexander Milne"
},
{
"title": "Hamlet",
"author": "William Shakespeare"
}
],
"description": {
"color": "black",
"material": "wood"
}
}
```
Simple manipulations
```
json.parse data > x
# 'found' returns an array empty (if the item wasn't found)
# or with one element (if the item was found).
# If the array isn't empty, the element in it is also a json
(x.found "books").at 0 > books
# 'with' operation puts the object in the field where we are now
x.with key some-json > new-x
stdout > @
sprintf
"In the %s %s I took a book called %s"
((((x.found "description").at 0).found "color").at 0).as-string
((x.found "essence").at 0).as-string
(((books.at 0).found "title").at 0).as-string
```
The creation a new json object
```
# creating of empty json object
json.object > x
# example of creating a filled json
with. > x2
with.
with.
json.of-object
"name"
json.of-string "shelf"
"color"
json.of-string "black wood"
"books"
with.
with.
json.of-array
with.
with.
json.of-object
"name"
json.of-string "War and Peace"
"age"
json.of-int 1869
with.
with.
json.of-object
"name"
json.of-string "Harry Potter"
"age"
json.of-int 1997
```
**x2** after the previous block of code
```
{
books: [
{name: "War and Peace", age: 1869},
{name: "Harry Potter", age: 1997}
],
name: "shelf",
color: "black wood"
}
```
## How to Contribute
Fork this repository, make changes, send us a [pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
```bash
$ mvn clean install -Pqulice
```
You will need Maven 3.3+ and Java 8+.