JSONExport is a desktop application for Mac OS X which enables you to export JSON objects as model classes with their associated constructors, utility methods, setters and getters in your favorite language.

Related tags

JSON JSONExport
Overview

JSONExport

JSONExport is a desktop application for Mac OS X written in Swift. Using JSONExport you will be able to:

  • Convert any valid JSON object to a class of one of the currently supported languages.
  • Preview the generated content before saving it.
  • Include constructors only, utility methods only, both or none.
  • Change the root class name.
  • Set a class name prefix for the generated classes.
  • Set package name for Java files.

Generated Files

Each generated file, besid the getters and setters (for Java) can include:

  • A constructor wich accepts an instance of NSDictionary, JSON, JSONObject instance depending on the file language, and the class will use this object to fill its properties data.
  • A utility method which converts the class data into a dictionary again.

Currently supported languages

Currently you can convert your JSON object to one of the following languages:

  1. Java for Android.
  2. Java for Realm Android.
  3. GSON for Android
  4. Swift Classes.
  5. Swift Classes for SwiftyJSON library.
  6. Swift Classes for Realm.
  7. Swift - CoreData.
  8. Swift Structures.
  9. Swift Structures for Gloss
  10. Swift Mappable Classes for (Swift 3) ObjectMapper
  11. Swift Structures for Unbox
  12. Objective-C - iOS.
  13. Objective-C - MAC.
  14. Objective-C - CoreData.
  15. Objective-C for Realm iOS.

Screenshot shows JSONExport used for a snippet from Twitter timeline JSON and converting it to Swift-CoreData. alt tag

Installation

Kindly clone the project, and build it using xCode 8 and above.

To Do

  • Support Objective-C Done
  • Sync multible classes with the same name or have the same exact properties Done
  • Support to parse JSON arrays of objects Done
  • Load JSON data from web
  • Open .json files from JSONExport
  • Supported languages management editor.
  • Beside raw JSON, load the model raw data from plist files as well.

Known Limitations:

  • When exporting to subclasses of NSManagedObject, some data types can not be exported. For example core data does not have data type for "array of strings"; in turn, if your JSON contains an array of strings, the exported file will not compile without you fixing the type mismatch.
  • When exporting subclasses of RLMObject, you will have to enter the default values of premitive types manually. This is because of dynamic properties limition that prevents you from having an optional premitive type.
  • When exporting to CoreData or Realm and you want to use the utility methods, you will need to manually watch for deep relation cycle calls; that is, when you convert an object to dictionary, this object try to convert one of its relation to a dictionary and the relation tries to convert the original object to a dictionary, that will cause a kind of cycle where each object involved calls the other object's toDictionary method infenitly...
  • Avoid attempt to model a JSON object with empty values, because JSONExport does not understand empty values and can not guess their types.
  • Deep nesting of arrays and objects will not be exported in a proper model files.

Final Note

The application still in its early stage. Please report any issue so I can improve it.

License

JSONExport is available under custom version of MIT license.

Comments
  • Inherit and note

    Inherit and note

    what about a model like this

    #import "BaseModel.h"
    
    @interface ZXPosition : BaseModel
    /**
     *  职务id
     */
    @property (nonatomic , assign) NSInteger gid;
    /**
     *  学校id
     */
    @property (nonatomic , assign) NSInteger sid;
    /**
     *  职务名称
     */
    @property (nonatomic , copy) NSString *name;
    /**
     *  描述
     */
    @property (nonatomic , copy) NSString *desinfo;
    /**
     *  职务人数
     */
    @property (nonatomic , assign) NSInteger typeNumber;
    @property (nonatomic , copy) NSString *date_str;
    /**
     *  职务作息列表
     */
    @property (nonatomic , strong) NSArray *sgaLit;
    @end
    
    opened by StephenZhuang 15
  • Support dark mode

    Support dark mode

    Issue :construction:

    • Checkbox text isn't visible when dark mode is enabled.
    • Mac Mojave with dark mode enabled

    Current Behavior :mag:

    • 'Constructor' and other checkbox text isn't visible.

    Steps to Reproduce

    1. Run JsonExport using Mojave with dark mode enabled.

    Screen shots

    screen_shot_2018-11-25_at_3_14_40_pm
    opened by kevnm67 5
  • In the App Store?

    In the App Store?

    just fyi: https://itunes.apple.com/app/json-modeler/id991244863?mt=12

    If it's not related to you: I hate it, when people just take OpenSource in order to make money..

    👍 for JSONExport

    opened by winkelsdorf 5
  • Feature request - Realm (& Core Data)

    Feature request - Realm (& Core Data)

    Realm Object - http://realm.io/docs/cocoa/0.80.0/api/Classes/RLMObject.html

    .. & Core Data NSManagedObject.

    Realm is also cross-platform with Android: http://realm.io/docs/java/0.70.1/#models

    opened by cannyboy 5
  • For dictionaries, getting wrong data types (Swift - structs)

    For dictionaries, getting wrong data types (Swift - structs)

    { "page_name": "Security Question validation", "page_flow": "forgot_password", "header": "Forgot your password?", "sub_header": "Just answer your security question", "fields": { }, "links": { }, "buttons": { } } screen shot 2016-10-26 at 3 34 01 pm

    opened by 04it212 4
  • How to use JSONExport for array of array type of service?

    How to use JSONExport for array of array type of service?

    {"responseString":"Success","errorCode":1,"result":[[{"videoName":"Video Test","description":"Video Test","videoImage":"http://t1.gstatic.com/images?q=tbn:ANd9GcQrRQrJ2OmPJNpwH6MU6pGSJGoYMVgOyozopoU3xgTtoUqxcbQM","categoryId":"1","categoryName":"TV Show","count":2},{"videoName":"video test 4","description":"Video Test","videoImage":"http://theonlinejournalist.com/wp-content/uploads/2015/05/Priyanka-Chopra.jpg","categoryId":"1","categoryName":"TV Show","count":2}],[{"videoName":"Video Test 2","description":"Video Test","videoImage":"http://lifestylesz.com/wp-content/uploads/2014/02/Priyanka-Chopra.jpg","categoryId":"2","categoryName":"Band","count":3},{"videoName":"video test 3","description":"Video Test","videoImage":"http://media.glamsham.com/download/wallpaper/celebrities/images/p/priyanka-chopra-wallpaper-114-12x9.jpg","categoryId":"2","categoryName":"Band","count":3},{"videoName":"video test 5","description":"Video Test","videoImage":"http://en.dailypakistan.com.pk/wp-content/uploads/2015/03/priyanka-chopra-4225-1680x1050.jpg","categoryId":"2","categoryName":"Band","count":3}],[{"videoName":"Test 1","description":"","videoImage":"http://myapne.com/news_images/news_1443449687_7899e1717e0698d6e50364_1.jpg","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 2","description":"","videoImage":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSIbOK6zbXK0PmxttPVVrh3hl6oYU9aQEXTPo32VRdn7Om3bir6","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 3","description":"","videoImage":"http://1.bp.blogspot.com/_uJ-SDPxtYh8/TClt5l6f72I/AAAAAAAAG0k/OdQv75Hyjbw/s1600/SONAM+kapoor+(2).jpg","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 4","description":"","videoImage":"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRs7UQlBc3BEyQjBwvNgYzQI4ZCSmVgmqqdWQ5jbsJB-u2yek3E","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 5","description":"","videoImage":"http://www.amicmaza.com/wp-content/uploads/2012/09/Simple-beautiful-girl.jpg","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 6","description":"","videoImage":"http://2.bp.blogspot.com/-dKYXsPrDeU8/T5ZD9NeNRfI/AAAAAAAAB2Y/P22RdR4-R48/s1600/pakistani+girls+photos+(645).jpg","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 7","description":"","videoImage":"http://www.pkhykia.com/wp-content/uploads/2014/02/Is-ko-kahte-ha-simple-girl.jpg","categoryId":"3","categoryName":"Music","count":8},{"videoName":"Test 9","description":"","videoImage":"http://1.bp.blogspot.com/-NbmHZvpPG74/TeDNcarKf5I/AAAAAAAAC1c/mRraMamUfNY/s1600/217554_103082809779610_100002336742079_28612_6306963_n.jpgg","categoryId":"3","categoryName":"Music","count":8}],[{"videoName":"Test 9","description":"Test","videoImage":"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT8ozJlGP6EKgpM_lz7VUSow_gxx6XYr9fSnmIeHj2X9ekCFFgV","categoryId":"4","categoryName":"Dance","count":5},{"videoName":"Test 10","description":"Test3","videoImage":"http://pakifashion.com/wp-content/uploads/2014/11/17736_452075081557853_83273622_n.jpg","categoryId":"4","categoryName":"Dance","count":5},{"videoName":"Test 11","description":"Test3","videoImage":"http://3.bp.blogspot.com/-fx6BSTnEmnI/VKpQFgmp48I/AAAAAAAAU14/sFI07qkFM8w/s1600/Bridal%2Bdress%2Bphoto%2B25.jpg","categoryId":"4","categoryName":"Dance","count":5},{"videoName":"Test 12","description":"Test3","videoImage":"http://2.bp.blogspot.com/-TiaZfzO6ocM/VIQB0422OwI/AAAAAAAAUfs/bCTd1WeuoXw/s1600/Bridal%2BMehndi%2Bdesign%2Bphoto%2B261.jpg","categoryId":"4","categoryName":"Dance","count":5},{"videoName":"Test 12","description":"Test3","videoImage":"http://www.shaadi-direct.com/images/members/photos/65339_7287483429.jpg","categoryId":"4","categoryName":"Dance","count":5}]]}

    opened by sourabhsharmait 3
  • Fix crash by parsing ObjectiveC array

    Fix crash by parsing ObjectiveC array

    I changed the lines of code below in ObjectiveC-Mac.json and ObjectiveC-iOS.json for parsing array

    from:

    ![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]
    

    to:

    [dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSArray class]]
    

    This is important because if the object value sometimes can be an empty String @"", not a NSNull value, this will cause a crash.

    The comparison view of ObjectiveC-iOS.json doesn't look good, please see constructors section for detail.

    opened by WenchaoD 3
  • Overriding specific property types

    Overriding specific property types

    In our system we have a bunch of "type" fields which on the server and client are identified as ENUMs, but in between we use JSON and have to use strings for these fields.

    Are you considering any support for overriding property types on specific classes, så the auto-generated code will have this ENUM for specific fields?

    That would be nice - thanks!

    opened by esbenvb 3
  • JSONLint valid, but JSONExport Cannot parse

    JSONLint valid, but JSONExport Cannot parse

    This very JSON passed in JSONLint (http://jsonlint.com and https://zaa.ch/jsonlint/ ), but Cocoa report error Badly formed object around character 373,No value for key in object around character 50.

    [{
    	"city": "南京",
    	"cafes": [{
    		"name": "夫子庙店",
    		"addr": "秦淮区大石坝街32号(夫子庙东门)",
    		"poster": "http://www.sitcoffee.com/system/upload/201206/56f9552642d9bc0da2cff2dd8da9692d_t.jpg",
    		"oneword": "临岸而坐,秦淮之美一览无遗,一杯下午茶,或一杯香气四溢的咖啡,让你细细感悟这“江南锦绣之邦,金陵风雅之薮”的“十里秦淮”古韵魅力。",
    		"opening": "9:00-24:00",
    		"lng": "118.793210000045",
    		"lat": "32.0213900004372",
    		"phones": ["025-52266082"]
    	}, {
    		"name": "南大店",
    		"addr": "鼓楼区汉口路47号二楼(南大正南门)",
    		"poster": "http://www.sitcoffee.com/system/upload/201207/5f2d243960acad2b557c9e9f6fa88be7_t.jpg",
    		"oneword": "生活与享受交错变化的南方城市,将咖啡香气径自延伸到最大愉悦,与众多南京院校为邻的南大店,等候你用散步的时间来欣赏精彩。",
    		"opening": "8:30-24:00",
    		"lng": "118.778726",
    		"lat": "32.053496",
    		"phones": ["025-83597180"]
    	}]
    }]
    
    opened by hye 2
  • Mappable Not exporting to Swift 3 syntax

    Mappable Not exporting to Swift 3 syntax

    When exporting Constructors and Utilities class is not conforming to the updated swift 3 NSCoding , Mappable protocols. Also decodeObjectForKey and encodeObject have been renamed to decodeObject(forKey:) / encodeObject(_:forKey:)

    opened by jejernig 2
  • Swift - Mappable Issues

    Swift - Mappable Issues

    Firstly, with XCode 7 there have been updates to ObjectMapper's Mappable protocol, the init method is now generic and empty as follows:

    required init?(_ map: Map){
    }
    

    This should go along with #23

    Additionally there's an issue with how classes are being created for Mappable types, here's some example generated code:

    //
    //  Response.swift
    //  Model file Generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
    
    import Foundation
    
    class Response{
    
      var arbitraryCount : Int?
      var posts : [Post]?
      var meta : Meta?
    
    
      required init?(_ map: Map){
    
      }
    
      func mapping(map: Map)
      {
        arbitraryCount <- map["arbitrary_count"]
        if posts != nil{
          var dictionaryElements = [NSDictionary]()
          for postsElement in posts {
            dictionaryElements.append(postsElement.toDictionary())
          }
          dictionary["posts"] = dictionaryElements
        }
        if meta != nil{
          dictionary["meta"] = meta.toDictionary()
        }
    
      }
    
    }
    

    First and foremost is the lack of : Mappable after Response, it should look like

    class Response: Mappable {
    ...
    

    Secondly is the failure to simply map lists of mappable types. I have a Post and Meta mappable type and the code generated is unnecessary and doesn't even look like it'll work... It should look like:

    ...
      func mapping(map: Map)
      {
        arbitraryCount <- map["arbitrary_count"]
        posts          <- map["posts"]
        meta           <- map["meta"]
      }
    ...
    

    (The arbitraryCount was just stuck into the JSON to illustrate that proper Mappable syntax does work for primitive types)

    Still a very useful tool as its making it much easier to generate models for my complex types, I'm currently just manually fixing the above.

    opened by apocolipse 2
  • Add: Swift - Apollo Realm  Codable

    Add: Swift - Apollo Realm Codable

    For the people who use Apollo with Realm database, model generation provided.

    For more information about the Apollo you can check the website: https://www.apollographql.com/docs/ios

    opened by ebubekirsezer 0
  • App getting crash while passing proper json.

    App getting crash while passing proper json.

    image

    Hi, I am using your projects for generating swiftyJSON Model classes. Sometimes I am getting crash issues while passing the JSON format data. I am getting a crash issue while passing the following JSON data, please check it, bro.

      "status": true,
      "code": 200,
      "message": "Old Order History listing",
      "data": [
        {
          "id": 100,
          "orderid": 23432423,
          "datetime": "",
          "orderstatus": "completed / Pending / Running / closedbyadmin / closedbyuser",
          "paybleamount": 1234.09,
          "deliveryaddress": {
            "id": 123,
            "address": "",
            "addresstype": "google",
            "lat": 12345.09,
            "long": 12345.09
          },
          "community": {
            "id": 123,
            "title": "",
            "address": "",
            "shortdesc": "",
            "lat": 1234.09,
            "long": 1234.09
          },
          "coupon": {
            "id": 123,
            "title": "",
            "code": "",
            "discount": 123.09,
            "shortdesc": "",
            "details": "",
            "terms": "",
            "validdatetime": ""
          },
          "paymentmode": {
            "id": 123,
            "title": "Google Pay",
            "isdefault": true,
            "payment_type": "Third"
          },
          "review": {
            "rating": 4.5,
            "comments": ""
          },
          "delivery_date": "",
          "title": "",
          "invoice": "Invoice HTML format",
          "invoiceURL": "Invoice PDF format URL link for download or mail it.",
          "items": {
            "orders": [
              {
                "id": 123,
                "title": "",
                "itemimage": "",
                "gallery": [
                  "https://eastceylon.com/?gclid=EAIaIQobChMIm8GTosKH8gIVARCRCh1TTwZcEAAYASAAEgKX1PD_BwE"
                ],
                "shortdesc": "",
                "longdesc": "",
                "price": 123.09,
                "qty": 1,
                "cattegory": {
                  "id": 123,
                  "cat_name": ""
                },
                "sub_cattegory": {
                  "id": 123,
                  "cat_name": ""
                },
                "nutri_info": "",
                "terms": "",
                "info": "",
                "works": "",
                "isveg": true,
                "isPackage": false,
                "items": []
              }
            ],
            "meals": [
              {
                "id": 123,
                "title": "",
                "itemimage": "",
                "gallery": [
                  "https://eastceylon.com/?gclid=EAIaIQobChMIm8GTosKH8gIVARCRCh1TTwZcEAAYASAAEgKX1PD_BwE"
                ],
                "shortdesc": "",
                "longdesc": "",
                "price": 123.09,
                "qty": 1,
                "cattegory": {
                  "id": 123,
                  "cat_name": ""
                },
                "sub_cattegory": {
                  "id": 123,
                  "cat_name": ""
                },
                "nutri_info": "",
                "terms": "",
                "info": "",
                "works": "",
                "isveg": true,
                "isPackage": true,
                "items": [
                  {
                    "id": 123,
                    "title": "",
                    "itemimage": "",
                    "gallery": [
                      "https://eastceylon.com/?gclid=EAIaIQobChMIm8GTosKH8gIVARCRCh1TTwZcEAAYASAAEgKX1PD_BwE"
                    ],
                    "shortdesc": "",
                    "longdesc": "",
                    "price": 123.09,
                    "qty": 1,
                    "cattegory": {
                      "id": 123,
                      "cat_name": ""
                    },
                    "sub_cattegory": {
                      "id": 123,
                      "cat_name": ""
                    },
                    "nutri_info": "",
                    "terms": "",
                    "info": "",
                    "works": "",
                    "isveg": true,
                    "isPackage": false
                  }
                ]
              }
            ]
          }
        }
      ]
    }
    
    opened by hirenutico 0
  • In FileRepresenter.swift Line 484 crash

    In FileRepresenter.swift Line 484 crash

    lang.basicTypesWithSpecialFetchingNeedsTypeCast, If this value is nil, it will crash,So I made a little adjustment, I don’t know if it is correct.

    guard let castArray = lang.basicTypesWithSpecialFetchingNeedsTypeCast else { return propertyStr } // if needs cast let cast = castArray[index]

    opened by YaHoYii 0
Owner
Ahmed Ali
Ahmed Ali
ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Tristan Himmelman 9k Jan 2, 2023
HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

Alibaba 4.1k Dec 29, 2022
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

John Lui 454 Oct 30, 2022
AlamofireObjectMappe - An Alamofire extension which converts JSON response data into swift objects using ObjectMapper

AlamofireObjectMapper An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper. Usage Given a U

Tristan Himmelman 2.6k Dec 29, 2022
An extension for Alamofire that converts JSON data into Decodable objects.

Swift 4 introduces a new Codable protocol that lets you serialize and deserialize custom data types without writing any special code and without havin

Nikita Ermolenko 749 Dec 5, 2022
JSONJoy - Convert JSON to Swift objects

JSONJoy Convert JSON to Swift objects. The Objective-C counterpart can be found here: JSONJoy. Parsing JSON in Swift has be likened to a trip through

Dalton 350 Oct 15, 2022
🌟 Super light and easy automatic JSON to model mapper

magic-mapper-swift ?? Super light and easy automatic JSON to model mapper Finish writing README.md Ability to map NSManagedObject Ability to convert m

Adrian Mateoaea 26 Oct 6, 2019
Mappable - Flexible JSON to Model converter, specially optimized for immutable properties

Mappable is a lightweight, flexible, easy-to-use framework to convert JSON to model, specially optimized for immutable property initializatio

Leave 27 Aug 26, 2022
Swift implementation of JMESPath, a query language for JSON.

Swift implementation of JMESPath, the JSON query language

Adam Fowler 30 Oct 19, 2022
Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. This app provide by the Core Data structure.

Capstone Project ?? About Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. Ad

Ensar Batuhan Unverdi 9 Aug 22, 2022
Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

JSONFeed Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https:/

Toto Tvalavadze 31 Nov 22, 2021
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Vanesa Giselle Korbenfeld 0 Oct 29, 2021
Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
A protocol to serialize Swift structs and classes for encoding and decoding.

Serpent (previously known as Serializable) is a framework made for creating model objects or structs that can be easily serialized and deserialized fr

Nodes - iOS 287 Nov 11, 2022
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.9k Dec 8, 2022
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.8k Nov 19, 2021
CryptoWatch is an application to fetch the currency datas from an api and show their updated values to user. User is able to get the coin datas without an extra effort.

CryptoTracker In order to combine my work and studies, I made a small project that keeps the user's registration datas in memory, checks them when nee

Ömer Faruk Kılıçaslan 2 Jun 27, 2022