question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

json with key "ids" is problematic?

See original GitHub issue

Now to be honest i’m a little bit confused, but when i do a call with

scope.myobj.post("merge", {"ids":"test"});

there is only an empty {} json object in the request body.

However if i change ids to something else, e.g.

scope.myobj.post("merge", {"ids2":"test"});

it works. I cleared browser cache and the myobj object is perfectly fine(every other request works, e.g. delete, put, get etc.).

I don’t think it is a restangular issue, but what could it be?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bostromcommented, Jan 8, 2017

@ngehlert as in the spec snippet above:

      Restangular.setRestangularFields({
        ids: '_ids' // set this to anything else then "ids"
      });

Now restangular will use a property called _ids on each restangularized object instead of the default ids, which is clashing with your object’s property. The documentation is a bit behind on this matter, I’ll try to update it with some better info.

The above is a global configuration when done like this. But you can scope the configuration also:

  var MyConfiguredRestangular = Restangular.withConfig(function (RestangularProvider) {
    RestangularProvider.setRestangularFields({
      ids: '_ids' // set this to anything else then "ids"
    });
  });
  // now you have a scoped configuration, use as normal Restangular
  var parent = MyConfiguredRestangular.restangularizeElement(null, {id: 1}, 'accounts', true);
  var child = MyConfiguredRestangular.restangularizeElement(null, {ids: 'test'}, null, false);
  parent.post('merge', child);
0reactions
ngehlertcommented, Jan 9, 2017

@bostrom awesome thanks 😄 well yeah it is actually quite easy then 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON: key items by id or not? - Stack Overflow
From my work experience, the former creates a real problem for clients (apps in my case) to parse the JSON data, as it...
Read more >
Relationships data object - id is not primary key - JSON API
So I just faced a problem when I do not use id as a primary key. I would need something like this (see...
Read more >
Problem with reserved resource attribute names #361 - GitHub
There are 4 reserved resource attribute names in JSON API: id , type , links ... It is very common to use column...
Read more >
Is it bad practice to use hyphens in JSON keys?
It is not really a bad practice, since JSON is language independent and therefore shouldn't be constrained by the syntax of any particular...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
The JavaScript exceptions thrown by JSON.parse() occur when string failed to be parsed as JSON.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found