# <img className="page-icon" src="/img/icons/jsonschema.svg" alt="" /> Import: JSON Schema

Creates a data contract from a [JSON Schema](https://json-schema.org/) file.

{/* AUTOGENERATED EXAMPLE: do not edit by hand; regenerate with the update script. */}

Given this [`orders.schema.json`](https://github.com/datacontract/datacontract-cli/blob/main/examples/imports/jsonschema/orders.schema.json):

```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "orders",
  "type": "object",
  "properties": {
    "order_id": { "type": "string", "description": "Unique identifier of the order." },
    "order_timestamp": { "type": "string", "format": "date-time" },
    "customer_id": { "type": "string" },
    "order_total": { "type": "integer" },
    "status": { "type": "string" }
  },
  "required": ["order_id", "order_timestamp", "customer_id", "order_total", "status"]
}
```

Run:

```bash
datacontract import jsonschema --source orders.schema.json
```

to produce the data contract:

```yaml
version: 1.0.0
kind: DataContract
apiVersion: v3.2.0
id: my-data-contract
name: orders
status: draft
schema:
- name: orders
  physicalType: object
  businessName: orders
  logicalType: object
  physicalName: orders
  properties:
  - name: order_id
    physicalType: string
    description: Unique identifier of the order.
    logicalType: string
    required: true
  - name: order_timestamp
    physicalType: string
    logicalType: string
    logicalTypeOptions:
      format: date-time
    required: true
  - name: customer_id
    physicalType: string
    logicalType: string
    required: true
  - name: order_total
    physicalType: integer
    logicalType: integer
    required: true
  - name: status
    physicalType: string
# …
```

{/* END AUTOGENERATED EXAMPLE */}

ODCS has no union type. A property that allows more than one type (`"type": ["string", "integer"]`, or several `anyOf`/`oneOf` branches) is imported as `logicalType: string` with the union in `physicalType` (`string|integer`), and the import prints a warning naming it. A single type plus `null` is not a union and imports as that type.

Local references (`$ref` to `#/$defs/…` or `#/definitions/…`, also at the root) are resolved, and the branches of an `allOf` are merged: their properties are combined, the schema's own first, and so are their `required` lists. A definition that contains itself stops at its first repetition, as an `object` without properties. References to other documents are not loaded. The import warns about both.

`const` becomes an `enum` with that one value, an object with `additionalProperties` but no `properties` becomes a `map`, `additionalProperties: false` at the root becomes the [custom property of the same name](../schema.md) that makes `datacontract test` fail on undeclared fields, and `minItems`, `maxItems`, `uniqueItems`, `multipleOf`, and `examples` are kept. Keywords ODCS cannot express, such as `patternProperties`, `if`, `not`, or `dependentRequired`, are left out with a warning that names the properties.

All options: **[`datacontract import jsonschema`](../commands/import/jsonschema.md)**.
