All Projects β†’ rakuyoMo β†’ JSONPreview

rakuyoMo / JSONPreview

Licence: MIT license
🎨 A view that previews JSON in highlighted form, it also provides the ability to format and collapse nodes.

Programming Languages

swift
15916 projects
shell
77523 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to JSONPreview

BetterMappable
Better Mappable through Property Wrappers using ObjectMapper
Stars: ✭ 26 (+23.81%)
Mutual labels:  swift-package-manager, swift5
Bettersegmentedcontrol
An easy to use, customizable replacement for UISegmentedControl & UISwitch.
Stars: ✭ 1,782 (+8385.71%)
Mutual labels:  swift-package-manager, swift5
EKAstrologyCalc
Astrology Calculator calculates moon's rise/set times, moon Age, moon phases and Zodiac Sign for location and time
Stars: ✭ 31 (+47.62%)
Mutual labels:  swift-package-manager, swift5
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (+47.62%)
Mutual labels:  swift-package-manager, swift5
Match3Kit
Library for simple Match3 games.
Stars: ✭ 38 (+80.95%)
Mutual labels:  swift-package-manager, swift5
TVToday
iOS TV Shows app with TMDb Api. RxSwift, MVVM, Clean Architecture. Tuist + Swift Package Manager
Stars: ✭ 27 (+28.57%)
Mutual labels:  swift-package-manager, swift5
core-data-model-description
Declarative way to describe a Core Data model in code.
Stars: ✭ 60 (+185.71%)
Mutual labels:  swift-package-manager, swift5
SETabView
SETabView is a TabBar with simple yet beautiful animations that makes your apps look cool!
Stars: ✭ 53 (+152.38%)
Mutual labels:  swift-package-manager, swift5
Table
CLI tables in Swift
Stars: ✭ 53 (+152.38%)
Mutual labels:  swift-package-manager, swift5
Swift-FFDB
a Object/Relational Mapping (ORM) support to iOS and MacOS .Since SwiftFFDB is build on top of FMDB.
Stars: ✭ 22 (+4.76%)
Mutual labels:  swift-package-manager, swift5
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-28.57%)
Mutual labels:  swift-package-manager, swift5
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (+19.05%)
Mutual labels:  swift-package-manager, swift5
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+419.05%)
Mutual labels:  swift-package-manager, swift5
Carekit
CareKit is an open source software framework for creating apps that help people better understand and manage their health.
Stars: ✭ 2,142 (+10100%)
Mutual labels:  swift-package-manager, swift5
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+228.57%)
Mutual labels:  swift-package-manager, swift5
Combinative
UI event handling using Apple's combine framework.
Stars: ✭ 106 (+404.76%)
Mutual labels:  swift-package-manager, swift5
errata
Source code error pretty printing
Stars: ✭ 41 (+95.24%)
Mutual labels:  highlight
EnumKit
EnumKit is a library that gives you the ability to simply access an enum associated value, without having to use pattern matching. It also offers many utilities available to other swift types, like updatability of an associated value and transformations.
Stars: ✭ 91 (+333.33%)
Mutual labels:  swift5
bow-openapi
🌐 Functional HTTP client generator from an OpenAPI/Swagger specification.
Stars: ✭ 47 (+123.81%)
Mutual labels:  swift-package-manager
PermissionDirector
a iOS permission manager writtern by Swift
Stars: ✭ 29 (+38.1%)
Mutual labels:  swift-package-manager

JSONPreview

δΈ­ζ–‡

JSONPreview inherits from UIView and implements functionality based on UITextView. You can use it to format your JSON data and highlight it for display.

Also JSONPreview provides fold and expand functionality, so you can collapse nodes that you are not interested in at the moment and re-display them at any time.

All of JSONPreview's features are written using native methods, which means you get a great experience on the Apple platform.

Screenshot

Here is a gif of about 25 seconds (about 2.5M) that shows the effect when using this library to preview JSON.

screenshot

Prerequisites

  • iOS 10 or later.
  • Xcode 10.0 or later required.
  • Swift 5.0 or later required.

Install

CocoaPods

pod 'JSONPreview'

Swift Package Manager

Or add the following to your Package.swift file:

dependencies: [
  .package(url: "https://github.com/rakuyoMo/JSONPreview.git", from: "1.3.6")
]

Features

In 1.3.0 version, we removed the ability to slide diagonally. Now if a JSON row is not displayed, it will be displayed folded instead of going beyond the screen. If you wish to use this feature, please use the 1.2.3 version

  • Support for formatted display of JSON data.

  • Support for highlighting JSON data, with various color and font configuration options.

  • Provide fold and expand for Array and Object.

  • Based on UITextView, meaning you can copy any content in JSONPreview.

  • JSONPreview provides limited, incomplete format checking functionality, so this feature is not provided as a main feature. For more details, please refer to: Format check

Usage

After downloading the project, ViewController.swift file contains part of the test code, just run the project Check the corresponding effect.

  1. Create the JSONPreview object and add it to the interface.
let previewView = JSONPreview()

view.addSubview(previewView)
  1. Call the preview(_:style:) method to preview the data in the default style:
let json = "{\"key\":\"value\"}"

previewView.preview(json)
  1. If you want to customize the highlight style, you can set it through the HighlightStyle and HighlightColor types:

Among them, ConvertibleToColor is a protocol for providing colors. Through this protocol, you can directly use the UIColor object, or easily convert such objects as 0xffffff, #FF7F20 and [0.72, 0.18, 0.13] to UIColor objects.

let highlightColor = HighlightColor(
    keyWord: ConvertibleToColor,
    key: ConvertibleToColor,
    link: ConvertibleToColor,
    string: ConvertibleToColor,
    number: ConvertibleToColor,
    boolean: ConvertibleToColor,
    null: ConvertibleToColor,
    unknownText: ConvertibleToColor,
    unknownBackground: ConvertibleToColor,
    jsonBackground: ConvertibleToColor,
    lineBackground: ConvertibleToColor,
    lineText: ConvertibleToColor
)

let style = HighlightStyle(
    expandIcon: UIImage?,
    foldIcon: UIImage?,
    color: highlightColor,
    lineFont: UIFont?,
    jsonFont: UIFont?,
    lineHeight: CGFloat
)

previewView.preview(json, style: style)

Format Check

Rendering

For rendering, JSONPreview only performs limited formatting checks.

The conditions that are known to trigger Error Rendering include

  • Value Unconventional JSON types. Supported types include object, array, number, bool, string, and null.
  • Checks for the number format, such as scientific notation and decimals.
  • Spell checking for true, false and null.
  • For scientific notation, the next node of {E/e} must be +, - or a number.
  • array elements are not separated by ,.
  • object elements are not separated by ,.
  • No : after the key of object.
  • object has : after the key but is missing the value.
  • The key of object is not a string.

In addition to the conditions explicitly mentioned above, other errors may also trigger an "error rendering". There may also be errors outside the scope of the formatting check that do not trigger "error rendering". However, they may lead to missing json content.

It is recommended that you do not rely too much on JSONPreview format checking, and use it to preview correctly formatted json whenever possible.

Link

The 1.2.0 version adds rendering of links. While rendering, JSONPreview performs a limited de-escaping operation.

The de-escaping operations supported by different versions are as follows:

If not otherwise specified, the following functions are cumulative.

  • 1.2.0: Support replacing "\\/" with "/".

Data Flow Diagram

DFD

TODO

  • Support Carthage.
  • Support for intel macOS.

Thanks

Thanks to Awhisper for his valuable input during the development of JSONPreview.

License

JSONPreview is available under the MIT license. For more information, see LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].