Develop Using Mock JSON Data

Use Mock JSON Data to test your queries and schemas

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and also easy for machines to parse. This tutorial will explain how to use StepZen to easily generate mock JSON data that can be used for designing queries and frontends without having to connect to a dedicated backend.

How to generate random, non-nested JSON mock data

Generate a flat JSON object containing a range of common data types. If you have an interface and define a query that returns that interface you can execute the query and get mock data back with types including:

  • String
  • Int
  • Float
  • JSON
  • Date
  • DateTime

Schema

Our schema creates a Test interface that includes a named type for each specified type. It also has a getTest query that returns a single Test object.

interface Test {
  String: String!
  Int: Int!
  Float: Float!
  JSON: JSON!
  JSON2: JSON!
  Date: Date!
  DateTime: DateTime!
}

type Query {
  getTest: Test
}

Query

Our MockJSON query runs the getTest query and returns a Test with all of the specified types.

query MockJSON {
  getTest {
    Date
    DateTime
    Float
    Int
    JSON
    JSON2
    String
  }
}

Query result

The query result looks like the following:

{
  "data": {
    "getTest": {
      "Date": "2020-03-30",
      "DateTime": "2029-05-09T12:14:04Z",
      "Float": 342.09990382693167,
      "Int": 275,
      "JSON": {},
      "JSON2": {
        "ihdt": "Suspendisse potenti",
        "joygwc": "469",
        "r": 578
      },
      "String": "Mauris massa"
    }
  }
}

Important caveats

  • You only get mock data on an interface, it does not work for a type.
  • The system automatically creates a concrete type named based on your interface such as Test__Mock.

This site uses cookies: By using this website, you consent to our use of cookies in accordance with our Website Terms of Use and Cookie Policy.