├── README.md ├── Sources └── JSONViewer │ ├── Configurations.swift │ ├── NodeSortingStrategies.swift │ ├── JSONViewer.swift │ ├── StringExtension.swift │ ├── JSONNode.swift │ └── JSONNodeView.swift ├── Package.swift ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # JSONViewer 2 | 3 | 4 | 5 | Use JSONViewer to view JSON as expandable and collapsable nodes in your SwiftUI Project 6 | 7 | **Usage** 8 | 9 | - To Convert JSON String to JSON Node 10 | 11 | 12 | 13 | ` var rootNode: JSONNode = "{"book":[{ "id":"111","language":"C", "edition":"First","author":"Dennis Ritchie" }]}".jsonNode` 14 | 15 | - To Show JSON Node in JSONViewer 16 | 17 | `JSONViewer(rootNode: rootNode)` 18 | 19 | - Demo 20 | 21 | https://github.com/varkrishna/JSONViewer/assets/13188037/c8d6a8d4-e05c-48e0-b169-f00193569d22 22 | 23 | - Integrate Using Swift Package Manager 24 | 25 | 26 | Search `https://github.com/varkrishna/JSONViewer` 27 | -------------------------------------------------------------------------------- /Sources/JSONViewer/Configurations.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by krishna varshney on 24/10/23. 6 | // 7 | 8 | import Foundation 9 | import SwiftUI 10 | 11 | public struct JSONViewerFontConfiguration: Equatable { 12 | 13 | let keyFont: Font 14 | let valueFont: Font 15 | 16 | public init(keyFont: Font, valueFont: Font) { 17 | self.keyFont = keyFont 18 | self.valueFont = valueFont 19 | } 20 | 21 | public init(with font: Font) { 22 | self.keyFont = font 23 | self.valueFont = font 24 | } 25 | 26 | public init() { 27 | self.init(with: .system(size: 14)) 28 | } 29 | 30 | } 31 | 32 | 33 | public enum InitialNodeExpandStrategy { 34 | case none 35 | case root 36 | case all 37 | 38 | // case uptoLevel(Int) 39 | // case arrayUptoLevel(Int) 40 | } 41 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.7 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "JSONViewer", 8 | platforms: [.iOS(.v16), .macOS(.v13)], 9 | products: [ 10 | // Products define the executables and libraries a package produces, and make them visible to other packages. 11 | .library( 12 | name: "JSONViewer", 13 | targets: ["JSONViewer"]), 14 | ], 15 | targets: [ 16 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 17 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 18 | .target( 19 | name: "JSONViewer", 20 | dependencies: []) 21 | ], 22 | swiftLanguageVersions: [.v5] 23 | ) 24 | -------------------------------------------------------------------------------- /Sources/JSONViewer/NodeSortingStrategies.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by krishna varshney on 25/10/23. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum SortingStrategy { 11 | case ascending 12 | case descending 13 | case none 14 | } 15 | 16 | class SortedDictionary: Sequence, IteratorProtocol { 17 | private let source: Dictionary 18 | private let strategy: SortingStrategy 19 | private var idx = -1 20 | 21 | private lazy var sortedData: ([Dictionary.Element]) = { 22 | switch strategy { 23 | case .ascending: 24 | return source.sorted(by: { $0.key < $1.key }) 25 | case .descending: 26 | return source.sorted(by: { $0.key > $1.key }) 27 | case .none: 28 | return source.map({$0}) 29 | } 30 | 31 | }() 32 | 33 | internal init(source: Dictionary, strategy: SortingStrategy) { 34 | self.source = source 35 | self.strategy = strategy 36 | } 37 | 38 | func makeIterator() -> SortedDictionary { 39 | return self 40 | } 41 | 42 | func next() -> (String, Any)? { 43 | idx += 1 44 | guard sortedData.indices.contains(idx) else { 45 | return nil 46 | } 47 | return (sortedData[idx].key, sortedData[idx].value) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/JSONViewer/JSONViewer.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public struct JSONViewer: View { 4 | @Binding var fontConfiguration: JSONViewerFontConfiguration 5 | private let rootNode: JSONNode 6 | private var initialNodeExpandStategy: InitialNodeExpandStrategy = .root 7 | private var actionHandler: ((JSONNodeActionEvents) -> Void)? = nil 8 | 9 | public init(rootNode: JSONNode, initialNodeExpandStategy: InitialNodeExpandStrategy = .root, actionHandler: ((JSONNodeActionEvents) -> Void)? = nil) { 10 | self.rootNode = rootNode 11 | self.initialNodeExpandStategy = initialNodeExpandStategy 12 | self.actionHandler = actionHandler 13 | self._fontConfiguration = Binding.constant(JSONViewerFontConfiguration()) 14 | } 15 | 16 | public init(rootNode: JSONNode, fontConfiguration: Binding, initialNodeExpandStategy: InitialNodeExpandStrategy = .root, actionHandler: ((JSONNodeActionEvents) -> Void)? = nil) { 17 | self.rootNode = rootNode 18 | self.initialNodeExpandStategy = initialNodeExpandStategy 19 | self._fontConfiguration = fontConfiguration 20 | self.actionHandler = actionHandler 21 | } 22 | 23 | public var body: some View { 24 | HStack { 25 | VStack { 26 | ScrollView { 27 | JSONNodeView(node: rootNode, 28 | level: 0, 29 | fontConfiguration: $fontConfiguration, 30 | initialNodeExpandStategy: self.initialNodeExpandStategy, actionHandler: self.actionHandler) 31 | } 32 | .scrollIndicators(.hidden) 33 | Spacer() 34 | } 35 | Spacer() 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/JSONViewer/StringExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Krishan Kumar Varshney on 01/07/23. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension String { 11 | func jsonNode(sortingStrategy: SortingStrategy = .none) -> JSONNode? { 12 | if let jsonData = self.data(using: .utf8) { 13 | do { 14 | let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) 15 | if let jsonDict = jsonObject as? [String: Any] { 16 | return self.createNode(key: "Root", value: jsonDict, sortingStrategy: sortingStrategy) 17 | } else if let jsonArray = jsonObject as? [[String: Any]] { 18 | return self.createNode(key: "Root", value: jsonArray, sortingStrategy: sortingStrategy) 19 | } else { 20 | return nil 21 | } 22 | } catch { 23 | return nil 24 | } 25 | } 26 | return nil 27 | } 28 | 29 | private func createNode(key: String, value: Any, sortingStrategy: SortingStrategy) -> JSONNode { 30 | var children: [JSONNode] = [] 31 | var type: JSONNodeType = .other 32 | if let dict = value as? [String: Any] { 33 | type = .object 34 | let sortedDict = SortedDictionary(source: dict, strategy: sortingStrategy) 35 | for (key, value) in sortedDict { 36 | children.append(createNode(key: key, value: value, sortingStrategy: sortingStrategy)) 37 | } 38 | } else if let array = value as? [Any] { 39 | type = .array 40 | for (index, item) in array.enumerated() { 41 | children.append(createNode(key: "\(index)", value: item, sortingStrategy: sortingStrategy)) 42 | } 43 | } else { 44 | children = [] 45 | } 46 | let jsonNodeValue = "\(value)" 47 | var node = JSONNode(key: key, value: jsonNodeValue, children: children) 48 | node.type = type 49 | return node 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/JSONViewer/JSONNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Krishan Kumar Varshney on 01/07/23. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum JSONNodeType { 11 | case object 12 | case array 13 | case other 14 | } 15 | 16 | public struct JSONNode: Identifiable, Hashable, Sequence { 17 | 18 | public static func == (lhs: JSONNode, rhs: JSONNode) -> Bool { 19 | return lhs.id == rhs.id 20 | } 21 | 22 | public func hash(into hasher: inout Hasher) { 23 | hasher.combine(id) 24 | } 25 | 26 | public init(key: String, value: String, children: [JSONNode]) { 27 | self.key = key 28 | self.value = value 29 | self.children = children 30 | } 31 | 32 | public let id = UUID() 33 | public var key: String 34 | public let value: String 35 | public var children: [JSONNode] 36 | public var type: JSONNodeType = .other 37 | 38 | public var isExpandable: Bool { 39 | return type != .other 40 | } 41 | 42 | public typealias Iterator = Array.Iterator 43 | 44 | public func makeIterator() -> Iterator { 45 | return children.makeIterator() 46 | } 47 | 48 | func jsonString(isChild: Bool = false, isArrayItem: Bool = false) -> String { 49 | var result = "" 50 | if !isChild { 51 | result += "{" 52 | } 53 | if !isArrayItem { 54 | result += "\"\(key)\":" 55 | } 56 | if !children.isEmpty { 57 | if type == .object { 58 | result += "{" 59 | for child in children { 60 | result += child.jsonString(isChild: true) 61 | result += "," 62 | } 63 | result.removeLast() 64 | result += "}" 65 | } else { 66 | result += "[" 67 | for child in children { 68 | result += child.jsonString(isChild: true, isArrayItem: true) 69 | result += "," 70 | } 71 | result.removeLast() 72 | result += "]" 73 | } 74 | } 75 | else if !value.isEmpty { 76 | result += "\"\(value)\"" 77 | } 78 | 79 | if !isChild { 80 | result += "}" 81 | } 82 | 83 | return result 84 | } 85 | } 86 | 87 | 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /Sources/JSONViewer/JSONNodeView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIView.swift 3 | // 4 | // 5 | // Created by Krishan Kumar Varshney on 01/07/23. 6 | // 7 | 8 | import SwiftUI 9 | 10 | public enum JSONNodeActionEvents { 11 | case onDoubleTap(node: JSONNode) 12 | } 13 | 14 | enum JSONNodeActionInternalEvents { 15 | case onToggle(node: JSONNode) 16 | case onDoubleTap(node: JSONNode) 17 | } 18 | 19 | public struct JSONNodeView: View { 20 | let node: JSONNode 21 | let level: Int 22 | private var initialNodeExpandStategy: InitialNodeExpandStrategy = .root 23 | @Binding var fontConfiguration: JSONViewerFontConfiguration 24 | @State var expandedNodes: [String: Bool] 25 | var actionHandler: ((JSONNodeActionEvents) -> Void)? 26 | 27 | internal init(node: JSONNode, level: Int, fontConfiguration: Binding, initialNodeExpandStategy: InitialNodeExpandStrategy, actionHandler: ((JSONNodeActionEvents) -> Void)? = nil) { 28 | self.node = node 29 | self.level = level 30 | self._fontConfiguration = fontConfiguration 31 | self.initialNodeExpandStategy = initialNodeExpandStategy 32 | self.actionHandler = actionHandler 33 | if initialNodeExpandStategy == .root && level == 0 { 34 | _expandedNodes = State(initialValue: ["Root": true]) 35 | } else if initialNodeExpandStategy == .all { 36 | _expandedNodes = State(initialValue: [node.key: true]) 37 | } else { 38 | _expandedNodes = State(initialValue: [:]) 39 | } 40 | } 41 | 42 | public var body: some View { 43 | VStack { 44 | if node.isExpandable { 45 | ExpandableJSONNodeView(fontConfiguration: $fontConfiguration, node: node, level: level, isExpanded: isExpandedNode(), initialNodeExpandStategy: initialNodeExpandStategy) { event in 46 | switch event { 47 | case .onToggle( _): 48 | toggleNodeState() 49 | case .onDoubleTap(let node): 50 | actionHandler?(.onDoubleTap(node: node)) 51 | } 52 | } 53 | } else { 54 | NonExpandableJSONNodeView(node: node, 55 | fontConfiguration: fontConfiguration, 56 | level: level) 57 | } 58 | } 59 | .contextMenu(menuItems: { 60 | Button { 61 | #if os(macOS) 62 | NSPasteboard.general.clearContents() 63 | if !node.isExpandable { 64 | NSPasteboard.general.setString("{\"\(node.key)\": \"\(node.value ?? "")\"}", forType: .string) 65 | } else { 66 | let jsonString = node.jsonString() 67 | NSPasteboard.general.setString(jsonString, forType: .string) 68 | } 69 | #elseif os(iOS) 70 | UIPasteboard.general.string = nil 71 | if !node.isExpandable { 72 | UIPasteboard.general.string = "{\"\(node.key)\": \"\(node.value ?? "")\"}" 73 | } else { 74 | let jsonString = node.jsonString() 75 | UIPasteboard.general.string = jsonString 76 | } 77 | #endif 78 | } label: { 79 | Text("Copy") 80 | } 81 | }) 82 | } 83 | 84 | func toggleNodeState() { 85 | if let value = self.expandedNodes[node.key] { 86 | self.expandedNodes[node.key] = !value 87 | } else { 88 | self.expandedNodes[node.key] = true 89 | } 90 | } 91 | 92 | func isExpandedNode() -> Bool { 93 | guard let value = self.expandedNodes[node.key] else { 94 | return false 95 | } 96 | return value 97 | } 98 | 99 | } 100 | 101 | private struct ExpandableJSONNodeView: View { 102 | @Binding var fontConfiguration: JSONViewerFontConfiguration 103 | 104 | let node: JSONNode 105 | let level: Int 106 | let isExpanded: Bool 107 | var initialNodeExpandStategy: InitialNodeExpandStrategy 108 | let actionHandler: (JSONNodeActionInternalEvents) -> Void 109 | 110 | var body: some View { 111 | VStack(alignment: .trailing) { 112 | HStack { 113 | Spacer() 114 | .frame(width: 32 * CGFloat(level)) 115 | HStack { 116 | nodeToggleButtonIcon() 117 | .onTapGesture { 118 | actionHandler(.onToggle(node: node)) 119 | } 120 | expandableNodeTypeLabel() 121 | Text(node.key) 122 | .font(fontConfiguration.keyFont) 123 | .onTapGesture(count: 2, perform: { 124 | actionHandler(.onDoubleTap(node: node)) 125 | }) 126 | } 127 | Spacer() 128 | } 129 | .frame(maxWidth: .infinity, maxHeight: .infinity) 130 | .buttonStyle(PlainButtonStyle()) 131 | 132 | if isExpanded { 133 | JSONNodeSuccessorView(fontConfiguration: $fontConfiguration, node: node, level: level, initialNodeExpandStategy: self.initialNodeExpandStategy) { event in 134 | switch event { 135 | case .onDoubleTap(let node): 136 | actionHandler(.onDoubleTap(node: node)) 137 | } 138 | } 139 | } 140 | } 141 | } 142 | 143 | func nodeToggleButtonIcon() -> some View { 144 | if isExpanded { 145 | return Image(systemName: "minus.circle.fill") 146 | .imageScale(.large) 147 | .font(fontConfiguration.keyFont) 148 | .frame(minWidth: 16, minHeight: 16) 149 | } else { 150 | return Image(systemName: "plus.circle.fill") 151 | .imageScale(.large) 152 | .font(fontConfiguration.keyFont) 153 | .frame(minWidth: 16, minHeight: 16) 154 | } 155 | } 156 | 157 | func expandableNodeTypeLabel() -> some View { 158 | if node.type == .object { 159 | return AnyView( 160 | Image(systemName: "curlybraces") 161 | .font(fontConfiguration.keyFont) 162 | .frame(minWidth: 16, minHeight: 16) 163 | ) 164 | 165 | } else if node.type == .array { 166 | return AnyView( 167 | Text("[ ]") 168 | .font(fontConfiguration.keyFont) 169 | .frame(minWidth: 16, minHeight: 16) 170 | ) 171 | } 172 | return AnyView(EmptyView()) 173 | } 174 | } 175 | 176 | private struct JSONNodeSuccessorView: View { 177 | @Binding var fontConfiguration: JSONViewerFontConfiguration 178 | 179 | let node: JSONNode 180 | let level: Int 181 | let initialNodeExpandStategy: InitialNodeExpandStrategy 182 | let actionHandler: (JSONNodeActionEvents) -> Void 183 | 184 | var body: some View { 185 | VStack(alignment: .trailing, spacing: 8) { 186 | ForEach(node.children) { childNode in 187 | HStack() { 188 | JSONNodeView(node: childNode, 189 | level: level + 1, 190 | fontConfiguration: $fontConfiguration, 191 | initialNodeExpandStategy: self.initialNodeExpandStategy, actionHandler: self.actionHandler) 192 | } 193 | } 194 | } 195 | } 196 | } 197 | 198 | private struct NonExpandableJSONNodeView: View { 199 | let node: JSONNode 200 | let fontConfiguration: JSONViewerFontConfiguration 201 | let level: Int 202 | 203 | var body: some View { 204 | HStack { 205 | Spacer() 206 | .frame(width: (32 * CGFloat(level)) + 3) 207 | 208 | JSONNodeViewDot(fontConfiguration: fontConfiguration) 209 | .frame(maxHeight: .infinity, alignment: .top) 210 | 211 | JSONNodeViewData(node: node, fontConfiguration: fontConfiguration) 212 | Spacer() 213 | } 214 | } 215 | } 216 | 217 | private struct JSONNodeViewDot: View { 218 | let fontConfiguration: JSONViewerFontConfiguration 219 | var body: some View { 220 | VStack { 221 | Spacer() 222 | .frame(height: 4) 223 | Image(systemName: "circlebadge.fill") 224 | .font(fontConfiguration.keyFont) 225 | .frame(minWidth: 8, minHeight: 8) 226 | } 227 | } 228 | } 229 | 230 | private struct JSONNodeViewData: View { 231 | let node: JSONNode 232 | let fontConfiguration: JSONViewerFontConfiguration 233 | 234 | var body: some View { 235 | HStack(alignment: .top, spacing: 0) { 236 | Text("\(node.key)") 237 | .font(fontConfiguration.keyFont) 238 | Text(":") 239 | .font(fontConfiguration.keyFont) 240 | Text("\(node.value)") 241 | .font(fontConfiguration.valueFont) 242 | } 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------