title: Integrate JSON data with publishing process in gatsby-node.js
body: <p>I've created a function inside gatsby-node.js that creates links between users and locations and publishes them to the correct path based on the info from the markdown files.</p>
  
  <p>Now, I have a local data.json with a survey data for every user that I need to integrate into this function. </p>
  
  <p>I need to import data from the data.json and check - if the currently processed User page has a matching email address in data.json, then add the testimonials to the output data. I'm struggling to find a way of how to integrate this logic into the existing function.</p>
  
  <p>Node.js</p>
  
  <pre><code>const path = require("path");
  const { createFilePath } = require("gatsby-source-filesystem");
  const data = require("src/data/data.json");
  
  exports.createPages = ({ actions, graphql }) =&gt; {
      const { createPage } = actions;
  
      return graphql(`
          {
              allMarkdownRemark(limit: 1000) {
                  edges {
                      node {
                          id
                          fields {
                              slug
                          }
                          frontmatter {
                              templateKey
                              title
                              location
                          }
                      }
                  }
              }
          }
      `).then(result =&gt; {
          if (result.errors) {
              result.errors.forEach(e =&gt; console.error(e.toString()));
              return Promise.reject(result.errors);
          }
  
          const edges = result.data.allMarkdownRemark.edges;
  
          edges.forEach(edge =&gt; {
              const id = edge.node.id;
              const title = edge.node.frontmatter.title;
              const location = edge.node.frontmatter.location || null;
              createPage({
                  path: edge.node.fields.slug,
                  component: path.resolve(
                      `src/templates/${String(
                          edge.node.frontmatter.templateKey,
                      )}.js`,
                  ),
                  // query variables are passed in via the context
                  context: {
                      id,
                      title,
                      location,
                  },
              });
          });
      });
  };
  
  exports.onCreateNode = ({ node, actions, getNode }) =&gt; {
      const { createNodeField } = actions;
  
      if (node.internal.type === `MarkdownRemark`) {
          const value = createFilePath({ node, getNode });
          createNodeField({
              name: `slug`,
              node,
              value,
          });
      }
  };
  </code></pre>
  
  <p>JSON</p>
  
  <pre><code>[
    {
      "agreed": true,
      "email": "alex@test.com"
      "testimonials": [
        {
          "name": "Alex",
          "city": "Pedro",
          "state": "WA",
          "description": "Alex was very patient. He is one of the good guys!"
        }
      ]
    }
  ]
  </code></pre>