Skip to content
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

Added JSON string basic escaping #1

Merged
merged 5 commits into from
Feb 12, 2016
Merged

Added JSON string basic escaping #1

merged 5 commits into from
Feb 12, 2016

Conversation

DirectX
Copy link
Contributor

@DirectX DirectX commented Feb 9, 2016

Basic escaping is mandatory to correctly handle situations like <node>some "quoted" text</node>

func Test() {
    xml := strings.NewReader(`<?xml version="1.0" encoding="UTF-8"?><hello>world { "a": "b", "c": ["d", "e"] }</hello>`)

    if jsonBuffer, err := xml2json.Convert(xml); err == nil {
        log.Print(jsonBuffer)

        var obj interface{}

        err := json.Unmarshal(jsonBuffer.Bytes(), &obj)

        if err != nil {
            panic(err)
        }

        log.Print(obj)
    }
}

@basgys
Copy link
Owner

basgys commented Feb 10, 2016

It is definitely a good plan to escape strings, good work! :)

There are a couple of things to iron out though before merging it:

  1. Exclude the following commit from the PR DirectX@7408620 (attributes have to be prefixed to avoid name clash)
  2. Rename escapeJsonString to escapeJSONString (to please golint)
  3. Add your example to the tests

@basgys
Copy link
Owner

basgys commented Feb 12, 2016

@DirectX I would have love to see your example above in the tests, but I'm already happy with this PR. Thanks again :)

basgys pushed a commit that referenced this pull request Feb 12, 2016
Added JSON string basic escaping
@basgys basgys merged commit 84b9cf1 into basgys:master Feb 12, 2016
@basgys basgys added the bug label May 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants