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

Add to the format was originally JSON format support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

obetame
Copy link

@obetame obetame commented Aug 27, 2016

parse json data will get error message

First of all thank the author raynos for this tool.

var safeParse = require("safe-json-parse/callback");
var a = {
  name:"wowo"
}
safeParse(a,function(error,json){
  if(error){
    // get error operation
  }
})

But I tried to solve it myself.

safeParse(JSON.stringify(a),function(error,json){
  if(error){
    // get error operation
  }
})

So I improved it.

@Raynos
Copy link
Owner

Raynos commented Aug 29, 2016

I do not understand this change, can you add a failing test ?

@obetame
Copy link
Author

obetame commented Aug 30, 2016

failing test:

var a = {name:'wowo'}
safe(a,function(error,json){
  if(error){
    console.log(error);//get error message
    console.log(json);//get undefined message
  }
  else{
    console.log(json);
})

@Raynos
Copy link
Owner

Raynos commented Aug 30, 2016

That's expected, there should be no json if we have an error with parsing.

@obetame
Copy link
Author

obetame commented Aug 31, 2016

Sometimes I do not know my data format is JSON, so it will prompt the error.
I think we should not meet the security, but also should pursue the right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants