{"id":28522421,"url":"https://github.com/rakuyokit/jsonpreview","last_synced_at":"2025-07-15T13:19:01.022Z","repository":{"id":43666303,"uuid":"294057954","full_name":"RakuyoKit/JSONPreview","owner":"RakuyoKit","description":"🎨 A view that previews JSON in highlighted form, it also provides the ability to format and collapse nodes.","archived":false,"fork":false,"pushed_at":"2025-04-01T09:02:30.000Z","size":6131,"stargazers_count":72,"open_issues_count":1,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-14T07:53:03.450Z","etag":null,"topics":["cocoapods","collapse","highlight","ios","json","json-preview","swift","swift-package-manager","swift5"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RakuyoKit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-09T08:57:20.000Z","updated_at":"2025-04-22T05:06:48.000Z","dependencies_parsed_at":"2023-11-28T03:28:52.559Z","dependency_job_id":"b9040510-ec95-4ba0-8bcc-a986df4beabc","html_url":"https://github.com/RakuyoKit/JSONPreview","commit_stats":null,"previous_names":["rakuyomo/jsonpreview"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/RakuyoKit/JSONPreview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RakuyoKit%2FJSONPreview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RakuyoKit%2FJSONPreview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RakuyoKit%2FJSONPreview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RakuyoKit%2FJSONPreview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RakuyoKit","download_url":"https://codeload.github.com/RakuyoKit/JSONPreview/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RakuyoKit%2FJSONPreview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265437625,"owners_count":23765124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","collapse","highlight","ios","json","json-preview","swift","swift-package-manager","swift5"],"created_at":"2025-06-09T09:09:47.186Z","updated_at":"2025-07-15T13:19:00.999Z","avatar_url":"https://github.com/RakuyoKit.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/RakuyoKit/JSONPreview/master/Images/logo.png#gh-light-mode-only\" alt=\"JSONPreview\" title=\"JSONPreview\" width=\"1000\"/\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/RakuyoKit/JSONPreview/master/Images/logo_dark.png#gh-dark-mode-only\" alt=\"JSONPreview\" title=\"JSONPreview\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://swiftpackageindex.com/RakuyoKit/JSONPreview\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRakuyoKit%2FJSONPreview%2Fbadge%3Ftype%3Dswift-versions\"\u003e\u003c/a\u003e\n\u003ca href=\"https://swiftpackageindex.com/RakuyoKit/JSONPreview\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRakuyoKit%2FJSONPreview%2Fbadge%3Ftype%3Dplatforms\"\u003e\u003c/a\u003e\n\u003ca href=\"https://cocoapods.org/pods/JSONPreview\"\u003e\u003cimg src=\"https://img.shields.io/github/v/tag/RakuyoKit/JSONPreview.svg?include_prereleases=\u0026sort=semver\"\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/RakuyoKit/JSONPreview/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-black\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`JSONPreview` is a JSON preview component that allows you to **format** your JSON data and display it with **syntax highlighting**. Additionally, `JSONPreview` offers **fold and expand** functionality, allowing you to collapse nodes you're not currently focusing on and re-display them at any time.\n\n`JSONPreview` inherits from `UIView` and implements related features based on `UITextView`. The entire framework is entirely implemented based on native frameworks, which means when using this framework on Apple platforms, you can achieve a better user experience.\n\n## Preview\n\nBelow is a roughly 25-second gif (**approximately 2.5M**) demonstrating the effect of previewing JSON using this library.\n\n![screenshot](Images/screenshot.gif)\n\n## Installation\n\n### CocoaPods\n\n```ruby\npod 'JSONPreview'\n```\n\n### Swift Package Manager\n\n- Select File \u003e Swift Packages \u003e Add Package Dependency\n- Add https://github.com/RakuyoKit/JSONPreview.git\n- Select \"Up to Next Major\" with \"2.3.3\"\n\nOr add the following content to your `Package.swift` file:\n\n```swift\ndependencies: [\n  .package(url: \"https://github.com/RakuyoKit/JSONPreview.git\", from: \"2.3.3\")\n]\n```\n\n## Features\n\n- [x] Support for **formatting** JSON data.\n- [x] Support for syntax **highlighting** of JSON data, offering various color and font configuration options.\n- [x] **fold and expand** functionality for `Array` and `Object` (except tvOS).\n- [x] Allow setting the initial state of nodes, `.folded` or `.expand`.\n- [x] Implemented based on `UITextView`. This means you can copy any content from `JSONPreview`.\n- [x] Search the contents of JSON using text.\n- [x] Switch between displaying JSON with or without wrapping lines at any time.\n\n\u003e Additional Details:\n\u003e 1. `JSONPreview` provides limited and incomplete formatting checks, so this feature is not offered as a primary function. Details can be found in: [Format check](#format-check).\n\u003e 2. Version [1.2.0](https://github.com/RakuyoKit/JSONPreview/releases/tag/1.2.0) added support for rendering links. Alongside rendering, `JSONPreview` performs limited unescaping: supporting replacing `\"\\\\/\"` with `\"/\"`.\n\n## Usage\n\n\u003e After downloading the project, the [Demo](Demo) directory contains sample projects. You can run the project to see the corresponding effects.\n\n### Basic Usage and Default Configuration\n\n1. Create a `JSONPreview` object and add it to the interface:\n\n```swift\nlet previewView = JSONPreview()\nview.addSubview(previewView)\n```\n\n2. Call the `JSONPreview.preview` method to preview the data with the default style:\n\n```swift\nlet json = \"{\\\"key\\\":\\\"value\\\"}\"\npreviewView.preview(json)\n```\n\n### Custom Styles\n\nIf you want to customize the syntax highlighting style, you can set it using `HighlightStyle` and `HighlightColor`:\n\n\u003e [`ConvertibleToColor`](Sources/Entity/HighlightColor.swift#L126) is a protocol for providing colors. Through this protocol, you can directly use `UIColor` objects or easily convert values like `0xffffff`, `#FF7F20` and `[0.72, 0.18, 0.13]` into `UIColor` objects.\n\n```swift\nlet highlightColor = HighlightColor(\n    keyWord: ConvertibleToColor,\n    key: ConvertibleToColor,\n    link: ConvertibleToColor,\n    string: ConvertibleToColor,\n    number: ConvertibleToColor,\n    boolean: ConvertibleToColor,\n    null: ConvertibleToColor,\n    unknownText: ConvertibleToColor,\n    unknownBackground: ConvertibleToColor,\n    searchHitBackground: ConvertibleToColor?,\n    jsonBackground: ConvertibleToColor,\n    lineBackground: ConvertibleToColor,\n    lineText: ConvertibleToColor\n)\n\nlet style = HighlightStyle(\n    expandIcon: UIImage?,\n    foldIcon: UIImage?,\n    color: highlightColor,\n    lineFont: UIFont?,\n    jsonFont: UIFont?,\n    lineHeight: CGFloat,\n    boldedSearchResult: Bool\n)\n\npreviewView.preview(json, style: style)\n```\n\nYou can also configure the `initialState` parameter to set the initial state of JSON child nodes.\n\n```swift\n// By default, all nodes are initially in a collapsed state during preview.\npreviewView.preview(json, style: style, initialState: .folded)\n```\n\n## Format Check\n\nWhen rendering JSON, `JSONPreview` performs **limited** formatting checks.\n\nKnown conditions that trigger \"error rendering\" include:\n\n- Values of unconventional JSON types. Supported types are `object`, `array`, `number`, `bool`, `string`, and `null`.\n- Checking for formatting in `number`, such as scientific notation and decimals.\n- Spelling check for `true`, `false`, and `null`.\n- For scientific notation, the next node after `{E/e}` must be `+`, `-`, or a digit.\n- Missing `,` separators between elements in an `array`.\n- Missing `,` separators between elements in an `object`.\n- No `:` after a key in an `object`.\n- `object` has `:` after a key but lacks a value.\n- Keys in `object` are not strings.\n\nApart from the explicitly mentioned conditions, other errors might trigger \"error rendering\". Additionally, there could be some errors outside the scope of formatting checks that might **result in missing content** in the JSON.\n\nIt's recommended not to overly rely on the formatting check feature of `JSONPreview` and to use it for previewing correctly formatted JSON as much as possible.\n\n## Data Flow Diagram\n\n![DFD](Images/DFD.jpg)\n\n## Contribution\n\nYou might feel that updates to `JSONPreview` are infrequent, but rest assured, this project has not been abandoned or stopped - I am still following it.\n\nIf you encounter any issues while using it, please feel free to [let me know](https://github.com/RakuyoKit/JSONPreview/issues/new?template=Blank+issue), and I’ll respond and assist as soon as possible.\n\nAdditionally, if you’d like to submit a PR, please base your development on the [`develop`](https://github.com/RakuyoKit/JSONPreview/tree/develop) branch before submitting your code. Thank you for your support and contributions!\n\n## Thanks\n\nThanks to [Awhisper](https://github.com/Awhisper) for valuable insights during the development of `JSONPreview`.\n\n## License\n\n`JSONPreview` is available under the **MIT** license. For more information, see [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakuyokit%2Fjsonpreview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frakuyokit%2Fjsonpreview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakuyokit%2Fjsonpreview/lists"}