GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - kryptco/JSON: A simple library for parsing and serializing JSON to Swift data structures.

This repository was archived by the owner on Sep 11, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

31 Commits
31 Commits

Folders and files

NameName
Last commit message
Last commit date
JSON.xcodeproj
JSON.xcodeproj
 
 
JSON
JSON
 
 
JSONTests
JSONTests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
json-icon.png
json-icon.png
 
 

Repository files navigation

A simple library for parsing and serializing JSON to any Swift data structures. Complete style control with minimal changes.

Developed at KryptCo (https://krypt.co)

Install

We recommend managing dependencies with git submodules.

git submodule add [email protected]:KryptCo/JSON.git

Use

This library works with all Swift data structures (i.e Structs, Classes, and Enums).

To use with your data structures:

- JSON to Swift: implement JsonReadable.
- Swift to JSON: implement JsonWritable.
- Both: implement Jsonable

Examples

To convert data structures to JSON and back we do the following.

do {
    let car = Car(make: "Toyota", model: "Rav4", year: "2004")

    // Serialize to JSON data/string
    let carJson = try car.jsonString()

    // Init object from JSON
    let parsedCar = try Car(jsonString: carJson)
} catch {
    // catch errors here
}

To implement a struct that can be initialized from JSON or can be serialized to JSON we do the following.

struct Car:Jsonable {
    var make:String
    var model:String
    var year:Int

    // use the `~>` operator function
    // to easily parse json into stored properties
    // type inference makes the syntax simple

    init(json:Object) throws {
        make = try json ~> "make"
        model = try json ~> "model"
        year = try json ~> "year"
    }

    var object:Object {
        return ["make": make,
                "model": model,
                "year": year
        ]
    }
}

See more examples in JSONTests/TestTypes.swift

About

A simple library for parsing and serializing JSON to Swift data structures.

Resources

Readme
MIT license
Activity
Custom properties

Stars

6 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.