diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb
index 989fff8918eca130a56252d0647676b09f20649e..2fdcf8d7838d7e572066228abaa5cdd2d976d70a 100644
--- a/lib/gitlab/diff/position.rb
+++ b/lib/gitlab/diff/position.rb
@@ -73,8 +73,8 @@ module Gitlab
           diff_refs.complete?
       end
 
-      def to_json
-        JSON.generate(self.to_h)
+      def to_json(opts = nil)
+        JSON.generate(self.to_h, opts)
       end
 
       def type
diff --git a/lib/gitlab/git_access_status.rb b/lib/gitlab/git_access_status.rb
index 5a806ff6e0df59e196f51b4ded5fd41963679168..09bb01be694ff69a2934e5b2d236f07b5f475721 100644
--- a/lib/gitlab/git_access_status.rb
+++ b/lib/gitlab/git_access_status.rb
@@ -8,8 +8,8 @@ module Gitlab
       @message = message
     end
 
-    def to_json
-      { status: @status, message: @message }.to_json
+    def to_json(opts = nil)
+      { status: @status, message: @message }.to_json(opts)
     end
   end
 end
diff --git a/spec/lib/gitlab/diff/position_spec.rb b/spec/lib/gitlab/diff/position_spec.rb
index cf28628cb962fb1b66d61f2b0ffaf8623caff262..10537bea00830e3d641998277be1be7080d49d5f 100644
--- a/spec/lib/gitlab/diff/position_spec.rb
+++ b/spec/lib/gitlab/diff/position_spec.rb
@@ -338,4 +338,28 @@ describe Gitlab::Diff::Position, lib: true do
       end
     end
   end
+
+  describe "#to_json" do
+    let(:hash) do
+      {
+        old_path: "files/ruby/popen.rb",
+        new_path: "files/ruby/popen.rb",
+        old_line: nil,
+        new_line: 14,
+        base_sha: nil,
+        head_sha: nil,
+        start_sha: nil
+      }
+    end
+
+    let(:diff_position) { described_class.new(hash) }
+
+    it "returns the position as JSON" do
+      expect(JSON.parse(diff_position.to_json)).to eq(hash.stringify_keys)
+    end
+
+    it "works when nested under another hash" do
+      expect(JSON.parse(JSON.generate(pos: diff_position))).to eq('pos' => hash.stringify_keys)
+    end
+  end
 end