RSJSONViewer is a Swift package that allows you to view JSON in a navigable and interactive way using SwiftUI. It supports navigation through objects, arrays, strings, numbers, and null values present in a JSON, providing an elegant and easy way to explore the structure of a JSON document.
- Navigable display of JSON objects using
NavigationView. - Support for displaying the following JSON element types:
- Objects
- Arrays
- Strings
- Numbers
- Null values (
null)
- Simple setup using SwiftUI.
- iOS 17.0+ / macOS 11.0+
- Swift 5.3+
- Xcode 12+
You can add RSJSONViewer to your project using Swift Package Manager (SPM).
- In Xcode, go to
File > Add Packages. - Enter the repository URL:
https://github.com/rodrigosoldi/rsjsonviewer.git - Select the version or branch you want to use and add the package to your project.
-
Import the package in your Swift file:
import RSJSONViewer -
Use
RSJSONViewerin your SwiftUI View to display a JSON:struct ContentView: View { var body: some View { RSJSONViewer(json: """ { "name": "John", "age": null, "skills": ["Swift", null, "JavaScript"], "address": { "city": "New York", "zipcode": "10001" } } """) } }
The RSJSONViewer allows you to explore JSON data and navigate through objects and arrays, displaying the information in a list interface. You can customize and extend the package to add new features, such as support for additional data types or visual styling.
The RSJSONViewer is composed of the following components:
RSJSONViewer: The main view that takes the JSON string and displays it.JSONElement: A protocol that defines how each type of JSON element should be rendered.JSONObjectView: Displays JSON objects as lists of key-value pairs.JSONArrayView: Displays JSON arrays as lists of elements.JSONStringView: Displays JSON strings.JSONNumberView: Displays JSON numbers.JSONNullView: Displays null (null) elements.JSONElementFactory: A factory that creates instances of JSON elements from native Swift objects.
Contributions are welcome! Feel free to open issues, suggest improvements, or submit pull requests.
This project is licensed under the MIT License.
If you have any questions, suggestions, or feedback, feel free to reach out via email.
