1

I joined a project were we sell services for different providers through web, iOS and android apps. I am working on iOS. I was ask to display a purchase form via a web view and react by what is entered natively. I do so by intercepting the network communication but as you can imagine it is slow, error prone and just kind of stupid. I ask why it has to be done in this way, why I just cannot get the data and render the form myself natively, and I was told that soon also the android app will adapt this feature and as the form can slightly change for each providers that would be the easiest approach.

While I agree that it is easier to decide on the server which fields are needed for each call, I don't think that the logical conclusion is to request a html form and create hackish interception around it.

Before the implementation for android starts I want to propose another option:

Instead of rendering a website I want the server to create a JSON to describe the form, that than can easily be used at client-side to create the form. Basically a server generated view model.

My question is: is there some "standard" already how such a JSON should look like?

I imagine it something like this

{
  "form": {
    "action": {
      "action-name": "Send",
      "method": "POST",
      "target": "https://api.mydomain.com/purchase/"
    },
    "fieldsets": [{
      "fieldset-name": "personal information",
      "fields": [{
        "field": {
          "kind": "text-field",
          "field-name": "First Name",
          "validator": {
            "validator-name": "regex-validator",
            "arguments": [{
              "regex": ".{3:}"
            }]
          },
          "optional": false
        }
      }, {
        "field": {
          "kind": "text-field",
          "field-name": "Last Name",
          "validator": {
            "validator-name": "regex-validator",
            "arguments": [{
              "regex": ".{3:}"
            }]
          },
          "optional": false
        }
      }, {
        "field": {
          "kind": "text-field",
          "field-name": "Email",
          "validator": {
            "validator-name": "email-validator"
          },
          "optional": false
        }
      }, {
        "field": {
          "kind": "text-field",
          "field-name": "Confirm Email",
          "validator": {
            "validator-name": "email-validator"
          },
          "optional": false
        }
      }]
    }, {
      "fieldset-name": "Credit Card Data",
      "fields": [{
        "field": {
          "kind": "text-field",
          "field-name": "Credit Card Number",
          "validator": {
            "validator-name": "creditcard-number-validator"
          },
          "optional": false
        }
      }]
    }]
  }
}
1
  • JSON doesn't really have a schema the way XML does, it is essentially a serialized object based on the class specification. At least it should be, sometimes it is pieced together manually in code.
    – user22815
    Dec 24, 2014 at 16:09

1 Answer 1

2

I think the standard you are looking for is JSON Schema. It's not specific to forms, it's a more general specification for defining what a particular JSON format looks like (like an XML schema). There are a few solutions for creating forms with JSON Schema, like joshfire/jsonform.

5
  • I don't want to render a html site client side. I want to avoid html. Dec 24, 2014 at 16:14
  • @vikingosegundo is there some "standard" already how such a JSON should look like? -- JSON Schema is that standard. If you don't actually need to create forms, you could just look at joshfire/jsonform as an example of how JSON Schema would be applied to JSON representing a form.
    – Hey
    Dec 24, 2014 at 16:18
  • 2
    Hey, my understanding of the (quite verbose) question is that the TO wants to know if there's a JSON-based standard that describes how forms (input elements like textareas and checkboxes) are layed out. vikingosegundo, please confirm that by clarifying/updating your question. Dec 24, 2014 at 16:23
  • schemata are a way to define standards. I ask if there is something like a "standard" Dec 24, 2014 at 16:23
  • @vikingosegundo the way the jsonform project handles this (and some other projects), the schema actually defines the form. There is not some other format that describes the form and the schema defines that format; the schema defines the form directly.
    – Hey
    Dec 24, 2014 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.