Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToRFC8259 ¶ added in v0.63.0
ToRFC8259 converts JSONC (JSON with Comments) to valid JSON following RFC8259. It strips out comments and trailing commas while maintaining the exact character offsets as the input. This ensures that any JSON parser locations will map directly back to the original source file positions.
Both line numbers and character positions are preserved in the output. Comments and trailing commas are replaced with spaces without changing line counts.
Comments can be either: - Single-line: starting with // and continuing to the end of the line - Multi-line: starting with /* and ending with */
Trailing commas are allowed in JSONC but not in standard JSON, so they are replaced with spaces to maintain character offsets.
func UnmarshalJSONC ¶ added in v0.63.0
UnmarshalJSONC parses JSONC (JSON with Comments) data into the specified value. It first converts JSONC to standard JSON following RFC8259 and then unmarshals it. This is a convenience function that combines ToRFC8259 and Unmarshal.
The parser preserves line number information, which is essential for reporting errors at their correct locations in the original file.
Usage example:
type Config struct {
Name string `json:"name"`
Version string `json:"version"`
xjson.Location // Embed Location to get line number info
}
var config Config
if err := xjson.UnmarshalJSONC(data, &config); err != nil {
return err
}
Types ¶
type Location ¶
Location is wrap of types.Location. This struct is required when you need to detect location of your object from json file.
func (*Location) SetLocation ¶
type ObjectLocation ¶
ObjectLocation is required when you need to save Location for your struct.