FAQ
Hi,

Details: running Go 1.3.1 on Ubuntu Server 12.04 64bit

I'm writing a simple JSON schema tool and I'm encountering an odd issue
with the encoding/json package and how it unmarshals periods. Here is an
example of a JSON schema that fails:
{
   "id": "/schema/handlePercolateEvent",
   "$schema": "http://json-schema.org/draft-04/schema#",
   "$ref": "refs.json#/models/percolationMessage"
}

The error that occurs is on the "$ref" value of
"refs.json#/models/percolationMessage" and in particular the period. The
error that is returned is "invalid character '.' in string escape code".

However, when I change the JSON schema to
{
   "id": "/schema/handlePercolateEvent",
   "$schema": "http://json-schema.org/draft-04/schema#",
   "$ref": "refs#/models/percolationMessage"
}

everything works fine (so I remove ".json" from the "$ref" value).

I don't understand why this errors occurs. There is clearly a period in
the "$schema" value and that decodes without any issue.

The files are utf-8 (unix) encoded so I don't believe that this is an file
encoding problem. The actual code that throws the error is
     var document interface{}
     err = json.Unmarshal(bodyBuff, &document)
     if err != nil {
         return nil, err
     }

which comes from this file:
https://github.com/xeipuuv/gojsonschema/blob/6080170586490f144a78fdd3a6c5ee891730c9c2/getJsonHelpers.go#L71

Has anyone encountered this error before and is there a solution to this?

Thanks in advance,
Matt

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Dan Kortschak at Oct 2, 2014 at 8:24 pm
    I can't replicate that http://play.golang.org/p/HyFKHjJ1Md unless I add backslash before the dot (as expected from the json source) http://play.golang.org/p/lG4jw-FkqK.

    Are you sure you are not receiving text with that escape sequence?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 2, '14 at 6:49p
activeOct 2, '14 at 8:24p
posts2
users2
websitegolang.org

2 users in discussion

Matt Price: 1 post Dan Kortschak: 1 post

People

Translate

site design / logo © 2021 Grokbase