Skip to content

Commit c4e2197

Browse files
committed
contextjson: Add comment support
1 parent 677d613 commit c4e2197

17 files changed

Lines changed: 1495 additions & 102 deletions

common/json/comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type CommentFilter struct {
2929
pendingN int
3030
}
3131

32+
// Deprecated: use new contextjson instead
3233
func NewCommentFilter(reader io.Reader) io.Reader {
3334
return &CommentFilter{br: bufio.NewReader(reader)}
3435
}

common/json/context.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build !without_contextjson
2-
31
package json
42

53
import (

common/json/context_ext.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build !without_contextjson
2-
31
package json
42

53
import (
@@ -23,3 +21,27 @@ type ContextMarshaler interface {
2321
type ContextUnmarshaler interface {
2422
UnmarshalJSONContext(ctx context.Context, content []byte) error
2523
}
24+
25+
type (
26+
CommentKind = json.CommentKind
27+
CommentPlacement = json.CommentPlacement
28+
CommentPathKind = json.CommentPathKind
29+
CommentPathSegment = json.CommentPathSegment
30+
CommentPath = json.CommentPath
31+
CommentPosition = json.CommentPosition
32+
Comment = json.Comment
33+
CommentSet = json.CommentSet
34+
CommentMarshaler = json.CommentMarshaler
35+
CommentUnmarshaler = json.CommentUnmarshaler
36+
)
37+
38+
const (
39+
CommentKindLine = json.CommentKindLine
40+
CommentKindHash = json.CommentKindHash
41+
CommentKindBlock = json.CommentKindBlock
42+
CommentPlacementLeading = json.CommentPlacementLeading
43+
CommentPlacementTrailing = json.CommentPlacementTrailing
44+
CommentPlacementInner = json.CommentPlacementInner
45+
CommentPathKey = json.CommentPathKey
46+
CommentPathIndex = json.CommentPathIndex
47+
)

common/json/context_ext_std.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

common/json/internal/contextjson/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Forked from Go 1.25.9 encoding/json.
55
Local changes:
66

77
- context-aware marshal and unmarshal interfaces
8+
- JSONC comments by default
9+
- comment-aware context marshal and unmarshal interfaces
810
- concrete error path reporting
911
- trailing comma support for arrays and objects
1012
- ObjectKeys helper for decoded JSON object fields

0 commit comments

Comments
 (0)