Render JSON sink output with yojson#2
Merged
Merged
Conversation
Replace the hand-rolled Buffer-based JSON serialization in Scribe_sinks.Json with a yojson value built from the event, serialized via Yojson.Safe.to_string. The compact output and string escaping are byte-identical to the previous implementation, so the existing test_json_sink regression test passes unchanged. Add yojson as a dependency of the scribe.sinks library and the scribe package. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scribe_sinks.Jsonpreviously hand-rolled JSON serialization with aBuffer: manual string escaping, value rendering, and byte-by-byte assembly of the{level,message,fields}object. This replaces that logic withyojson, which already implements the same escaping rules correctly.The sink now builds a
Yojson.Safe.tvalue from the event and serializes it withYojson.Safe.to_string. The public interface (string_of_event,channel,stderr) and the exact output are unchanged.Changes
lib/sinks/json.ml: build and serialize a yojson value instead of writing to aBuffer(≈44 lines removed).lib/sinks/dune: addyojsonto the library's dependencies.dune-project/scribe.opam: declareyojsonin thescribepackage depends (opam file regenerated bygenerate_opam_files).Compatibility
Output is byte-identical to the previous implementation. yojson's compact writer produces spaceless output and uses the same escaping (
\",\\,\b,\f,\n,\r,\t,\u00xxfor control chars, UTF-8 passed through), and`Assocpreserves field order. The existingtest_json_sink, which pins the exact JSON line, passes unchanged.Verification
dune build,dune runtest,dune build @fmt, anddune build @installall pass.