11# TidyJSON
22
3- TidyJSON is a neat and tidy JSON package run on all Swift platforms (Linux, iOS, OS X)
3+ TidyJSON is a neat and tidy JSON package run on all Swift platforms (Linux, iOS, OS X, tvOS, watchOS )
44
55[ ![ Build Status] ( https://travis-ci.org/benloong/TidyJSON.svg?branch=master )] ( https://travis-ci.org/benloong/TidyJSON )
66
77## Goals
88- [x] simple, neat and tidy json lib
99- [x] safe static typed without ` AnyObject `
10+ - [x] performance
1011- [x] pure Swift, only dependent to builtin types
11- - [x] compatible with all Swift platforms (Linux, iOS, OS X)
12+ - [x] compatible with all Swift platforms (Linux, iOS, OS X, tvOS, watchOS )
1213- [x] concise usage
1314- [x] boxing dict and array type for mutating data
1415- [x] modify json via subscript operator
@@ -19,6 +20,9 @@ TidyJSON is a neat and tidy JSON package run on all Swift platforms (Linux, iOS,
1920## Usage
2021
2122### Literal Convertible
23+
24+ Literal value can be type safe converted to TidyJSON.JSON like this:
25+
2226``` swift
2327let jsonFalse : JSON = false
2428let jsonTrue : JSON = true
@@ -29,7 +33,10 @@ let jsonArray : JSON = [12, "string", false, nil, true, ["nested array", 12, 1.2
2933let json : JSON = [" key" : false , " key2" : true , " key3" : [1 , " hello" , 3 , " world" , [" key4" : nil , " key5" : 12.03 , " key6" : 12E-2 , " key7" : -12e-2 ]]]
3034```
3135
32- ### Update value
36+ ### Access value
37+
38+ Get and Set value via Subscripts:
39+
3340``` swift
3441var json : JSON = []
3542// []
@@ -64,21 +71,21 @@ json1["hello"] = false
6471json1[" world" ] = true
6572// {"hello":false, "world":true}
6673
74+ // remove a key
6775json1[" hello" ] = nil
6876// {"world":true}
6977
7078json1[" world" ] = [1 ,2 ,3 ]
7179// {"world":[1,2,3]}
7280```
7381
74-
7582### Parse from String
7683``` swift
7784let json1 = JSON.parse (" {\" key\" : false }" )
7885if let b = json1[" key" ].bool {
7986 print (b)
8087}
81- /* out
88+ /*
8289false
8390*/
8491
@@ -87,7 +94,7 @@ let json2 = JSON.parse("{\"key\" : [\" \\u0041334 \\n \\t \\\" \"]}")
8794if let x = json2[" key" ][0 ].string {
8895 print (x)
8996}
90- /* out
97+ /*
9198 A334
9299 "
93100*/
@@ -139,6 +146,12 @@ After install `XCTest`, run `sh run_test.sh`
139146
140147## Integration
141148
149+ #### Carthage
150+
151+ To integrate TidyJSON into your Xcode project using Carthage, specify it in your Cartfile:
152+
153+ github "benloong/TidyJSON"
154+
142155#### Swift Package Manager
143156
144157Currently support Swift Package Manager to install TidyJSON by adding the proper description to your Package.swift file:
0 commit comments