Releases: hjson/hjson-go
v4.4.0
Slightly changed behavior for unmarshalling "null" into a string destination: if the value is "null" without quotes and the destination is a pointer then the pointer is set to nil
instead of a pointer to the string "null", even if the destination is a pointer to a string or a type that implements UnmarshalText()
.
v4.3.1
Any control chars in map keys are now escaped in Hjson and JSON output.
Tested on Go 1.12 - 1.21
v4.3.0
Two new public structs of interest: hjson.OrderedMap and hjson.Node.
hjson.OrderedMap can be used as destination or source for all Hjson unmarshal and marshal functions (if the root value is a map/object), and also for the unmarshal and marshal functions of the standard package json
. hjson.OrderedMap is similar to map[string]interface{}
, but preserves key order.
hjson.Node can also be used as destination or source for all Hjson unmarshal and marshal functions, and also for the unmarshal and marshal functions of the standard package json
. The struct is simply a wrapper for the actual value and a helper struct containing any comments, allowing comments and custom indentation to be preserved if you read in a document, change a value, and then save the document again. hjson.Node has several convenience functions, for example AtIndex() or SetKey() that can be used when you know that the node contains a value of type []interface{}
or *hjson.OrderedMap.
Other changes:
- Added argument
-preserveKeyOrder
to the tool hjson-cli - Added field DisallowDuplicateKeys (default
false
, which means that later values overwrite earlier values) to the DecoderOptions struct - Added field WhitespaceAsComments (default
true
) to the DecoderOptions struct - hjson-go no longer supports Go 1.11
Tested on Go 1.12 - 1.19
v4.2.0
Retain key order in objects for UnmarshalJSON() and MarshalJSON() so that implementations of ordered maps can work.
New interface ElemTyper allows custom containers implementing UnmarshalJSON() to let hjson.Unmarshal() know what type of elements they will contain, so that hjson.Unmarshal() can unmarshal numbers, booleans and null into strings if needed by the custom container.
Tested on Go 1.11 - 1.19
v4.1.0
Type ambiguity due to quoteless strings can now be avoided by using typed destinations when unmarshalling. A string destination will receive a string even if the quoteless string also was a valid number, boolean or null. Previously an error would have been returned, for example "cannot unmarshal number into Go value of type string".
Tested on Go 1.11 - 1.19
v4.0.0
Now uses go.mod
. New import path for the package:
import "github.com/hjson/hjson-go/v4"
Tested on Go 1.11 - 1.18
Breaking changes
- Non-exported struct fields are now ignored.
- Promoted struct fields (fields that belong to embedded structs) are now encoded as direct members on the object into which the fields were promoted. This makes the behavior of hjson.Marshal() the same as the behavior of json.Marshal() in this regard.
- If a type implements encoding.TextMarshaler but not json.Marshaler then the function MarshalText() will be called on it to get a text representation. Both for values and map keys.
\r
is no longer removed from strings. If a string contains\r
it will not be encoded into a multi-line string but instead a quoted string.- Releases now contain the hjson tool for a lot more architectures. The tool is distributed as compressed archives instead of uncompressed executables.
- hjson.Unmarshal() now converts the Hjson input into JSON and then uses a json.Decoder to unmarshal it. This means that hjson.Unmarshal() now can unmarshal to structs, but also that the destination tree is kept if possible. Values are merged into the destination tree instead of always replacing it at the root.
- The default value of BracesSameLine in EncoderOptions returned by DefaultOptions() has been changed from
false
totrue
. - Encoder options AllowMinusZero and UnknownAsNull have been removed. They never had any effect.
- The flag
-allowMinusZero
has been removed from the hjson tool. It never had any effect.
New features
- New functions UnmarshalWithOptions() and DefaultDecoderOptions(). Possible options are UseJSONNumber and DisallowUnknownFields, both having
false
as default value.
v3.3.0
Fix for building version 3 of hjson-go. Requires export GO111MODULE=auto
when building or testing using Go 1.16 or later, and that the module is placed in ~/go/src/github.com/hjson/hjson-go
or other folder dictated by the local Go environment.
v3.2.0
Can unpack pointers to pointers to strings.
Added and re-enabled encoder options:
- EmitRootBraces works again.
- QuoteAmbiguousStrings can be set to false in order to not quote strings even if they will be identical to numbers, booleans or null.
- BaseIndentation can be used to add an indentation to every line in the output.
v3.1.1
Releases now contain hjson-cli binaries for Linux, macOS and Windows.
Release v3.1.0
Implement Marshal for structs, with support for comments in structs:
type foo struct {
a A `comment:"First comment"`
b B `comment:"Second comment"`
}
Additional minor bug fixes.
- Fix panic when passing nil to Unmarshal
- Bug fix for marshal of unsigned types
- Bug fix for README add closing block for code section
- Use custom Marshaler if type implements Marshal interface
- Add unit tests for Marshal. encode.go coverage at 94.9%