{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.motive.co/schemas/motive-feed.json",
  "title": "Motive product feed (JSON)",
  "description": "Validation file for product feeds in Motive format. Checks the recommended structure of a product feed in Motive format, with the key names used in the docs examples. Validates a JSON feed (an object with a products array) or a single line of a JSONL feed (one product).",
  "type": "object",
  "if": {
    "required": [
      "products"
    ]
  },
  "then": {
    "properties": {
      "products": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/product"
        }
      }
    }
  },
  "else": {
    "$ref": "#/$defs/product"
  },
  "$defs": {
    "product": {
      "type": "object",
      "required": [
        "id",
        "name",
        "url",
        "images",
        "price",
        "availability"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "images": {
          "$ref": "#/$defs/images"
        },
        "price": {
          "$ref": "#/$defs/price"
        },
        "availability": {
          "$ref": "#/$defs/availability"
        },
        "category": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/categoryPath"
          }
        },
        "code": {
          "$ref": "#/$defs/code"
        },
        "brand": {
          "type": "string"
        },
        "product_labels": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "text": {
                "type": "string"
              }
            }
          }
        },
        "variation": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/variant"
          }
        }
      },
      "additionalProperties": true
    },
    "variant": {
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "is_default": {
          "type": "boolean"
        },
        "price": {
          "$ref": "#/$defs/price"
        },
        "availability": {
          "$ref": "#/$defs/availability"
        },
        "images": {
          "$ref": "#/$defs/images"
        }
      },
      "additionalProperties": true
    },
    "images": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "alt": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "price": {
      "type": "object",
      "required": [
        "regular"
      ],
      "properties": {
        "regular": {
          "$ref": "#/$defs/amount"
        },
        "on_sale": {
          "anyOf": [
            {
              "$ref": "#/$defs/amount"
            },
            {
              "type": "null"
            }
          ]
        },
        "is_price_from": {
          "type": "boolean"
        }
      },
      "additionalProperties": true
    },
    "availability": {
      "description": "Stock as an object, where allow_order defaults to stock > 0, or as just the units in stock.",
      "oneOf": [
        {
          "type": "object",
          "required": [
            "stock"
          ],
          "properties": {
            "stock": {
              "$ref": "#/$defs/stock"
            },
            "allow_order": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "enum": [
                    "true",
                    "false"
                  ]
                }
              ]
            }
          },
          "additionalProperties": true
        },
        {
          "$ref": "#/$defs/stock"
        }
      ]
    },
    "categoryPath": {
      "description": "Levels separated by |>. Each level can start with an ID followed by |. For example: 2|Home|>3|Clothes or Home|>Clothes.",
      "type": "string",
      "pattern": "^(?:(?!\\|>).)+(?:\\|>(?:(?!\\|>).)+)*$"
    },
    "code": {
      "type": "object",
      "properties": {
        "mpn": {
          "type": "string"
        },
        "gtin": {
          "type": "string"
        },
        "isbn": {
          "type": "string"
        },
        "upc": {
          "type": "string"
        },
        "reference": {
          "type": "string"
        },
        "ean13": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "amount": {
      "description": "A number, or a text with one number, such as 19.99, \"19,99\" or \"19.99 EUR\". A text with several numbers or separators, such as \"1.234,56\", is discarded.",
      "oneOf": [
        {
          "type": "number",
          "minimum": 0
        },
        {
          "type": "string",
          "pattern": "^[^0-9]*[0-9]+[,.]?[0-9]*[^0-9]*$"
        }
      ]
    },
    "stock": {
      "description": "Units in stock. Negative values count as 0.",
      "oneOf": [
        {
          "type": "integer"
        },
        {
          "type": "string",
          "pattern": "^-?[0-9]+$"
        }
      ]
    }
  }
}
