-
Notifications
You must be signed in to change notification settings - Fork 126
feat: json-records content type support #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pimterry
merged 13 commits into
httptoolkit:main
from
WeihanLi:json-records-content-type
Aug 7, 2025
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3b91be8
feat: json-records content type support
WeihanLi cce16cd
refactor: remove unnecessary toString convert
WeihanLi 62c666b
refactor: remove unnecessary import
WeihanLi c074475
docs: add a comment for the SignalR record separator
WeihanLi f2dafbf
feat: akip add json when already has json-records
WeihanLi 549367b
feat: add json-records language
WeihanLi 6b97ffe
update line number
WeihanLi 02ccb3b
update line number as splits index
WeihanLi f982a19
Use JSON record line & character details in validation
pimterry 1f84472
Extract content validation + extend JSON record validation & detection
pimterry 0ae61fe
Add magic forgiving JSON formatting for normal & record JSON
pimterry 5e317c7
cleanup unused splitBuffer method
WeihanLi 1adda66
revert buffer.ts
WeihanLi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this approach, we're parsing & converting the JSON records to a sort-of equivalent JSON array, and then just showing that as JSON content.
This sort of works but it would be better to create a separate language I think. There's a few problems here I can see already:
[ ... ]
but you haven't really.language
{}�{{...
unformatted string, which then just shows errors for the record separator characters (not the actual error in the content). We should be able to split & format the messages regardless of JSON parsing, and show nice errors inline.Did you take a look at the XML support code? I think the same thing should be possible. If you want to look at Monaco's code for JSON support itself, the entrypoint is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think the
JSON-records
is a kind of variant of JSON, so I reused thejson
language. Let me try to update this with a separate languageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the jsonc-parser did not support return the error line number/column number info, any suggestion?
https://github.com/microsoft/node-jsonc-parser/blob/7eba2392a9aecb76fc150705454ce277dc7b7f6b/src/impl/parser.ts#L162
https://github.com/microsoft/node-jsonc-parser/blob/main/src/main.ts#L143
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I thought it did, and it has the internals but it doesn't expose that as you'd expect. I've just opened a PR to fix that jsonc-parser: microsoft/node-jsonc-parser#102.
No way to know how long that'll take to merge & release though, so better to assume we don't have it in the meantime. It's easy to work around though: you can copy the definition of
parse
in directly (from my PR there, so it includes the error line details) since it's just a small wrapper aroundjsoncParser.visit
. Once/if the PR above is merged we can drop that and usejsoncParser.parse
directly instead.