0

I have a Parse cloud-code function that is resident in Heroku. I want to create a Parse object from the json that is passed to Heroku, so I'm using the Parse.Object fromJSON() function to try to do this:

var Vendor = Parse.Object.extend("Vendor");
var vendor = new Vendor();

var myVendor = vendor.fromJSON(json);

The above code fails at the final line, with the error message:

2015-12-01T02:18:05.446656+00:00 app[web.1]:    var myVendor = vendor.fromJSON(json);
2015-12-01T02:18:05.446656+00:00 app[web.1]:                          ^
2015-12-01T02:18:05.446657+00:00 app[web.1]: TypeError: undefined is not a function.  

Any ideas why I can't get this function working?

6
  • 1
    Looks like you have to call .fromJSON() in the JSON object (docs: parse.com/docs/js/api/classes/…), but I can't help you any more... I have no experience in Parse. Commented Dec 1, 2015 at 2:28
  • 1
    @AlejandroIván you beat me too it! Commented Dec 1, 2015 at 2:29
  • Sorry, don't fully understand what you mean by having to call .fromJSON() "in the JSON object" Commented Dec 1, 2015 at 2:32
  • Have you tried var myVendor = Parse.Object.fromJSON(json) Commented Dec 1, 2015 at 2:32
  • Yep, exact same error: var user = Parse.Object.fromJSON(json); Undefined is not a function. Commented Dec 1, 2015 at 2:35

1 Answer 1

1

If you can't get fromJSON working then I'd suggest looping over each key in your JSON object and then using Parse's set method to assign the value for that key, at which point you could do:

// Set the key/value on the object for each entity in the json objet
for(var key of json) 
    vendor.set(key, json[key])

vendor.save(null, {
    success: function(newVendor) {
        console.log(newVendor)
    },
    error: function(error) {
        console.log(error.message)
    }
})

Please bear in mind that I've written this from my phone, so I have not tested the output, but I believe this should be the general direction you go with this problem.

I hope it helps/works.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I really only need the Parse Object without data. I'm using it to set the field for one of my link (relationship) classes. I stumbled on the fromJSON function when perusing the docs and got frustrated when I couldn't get it working. Thanks again for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.