Code Monkey home page Code Monkey logo

eo-json's Introduction

EOLANG objects for JSON parsing.

The main idea is that everything is a json

This is how create json object

+alias org.eolang.io.stdout
+alias org.eolang.txt.sprintf
+alias org.eolang.fs.json
+alias org.eolang.collections.map

# The first way is to parse the text
json.parse "there should be a json string" > x

# The second way is to wrap the map
json.wrap map > x

JSON string for the following examples (the name of the string is data)

{
  "id": 1,
  "books": [
    {
      "title": "Winnie the Pooh",
      "author": "Alexander Milne"
    },
    {
      "title": "Hamlet",
      "author": "William Shakespeare"
    }
  ],
  "description": {
    "color": "black",
    "material": "wood"
  }
}

Simple manipulations

json.parse data > x

# 'leaf' takes one or more values, and deepens along the specified path
# if an object with this name did not exist, it creates an empty json object
x.leaf "books" > books

# 'write' operation puts the object in the field where we are now
(x.leaf "essence").write "bookcase"

stdout > @
  sprintf
    "In the %s %s I took a book called %s"
    (x.leaf "description" "color").as-string
    (x.leaf "essence").as-string
    ((books.get 0).leaf "title").as-string 

The creation and use of a new json object

# creating of empty json object
json.parse "{}" > x

(x.leaf "age").write 20
  
(x.leaf "state").write "good"

x after the previous block of code

{
  "age": 20,
  "state": "good"
}

eo-json's People

Contributors

eugenedar avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.