0

Why does this request have a JSON content:

$http.put<void>(path,  { data: 156 } , Config)

But this doesn't (It does have an empty JSON content)

http.put<void>(path, 156, Config)

?

Doesn't alone numbers are valid JSON too?

The Config variable just holds the session token and the Key parameter

Explanation: I have a configuration service that allows me to save Key-Value pairs on the server side. This are stored as JSON text on the database in a way that the client can save any object and then retrive it by its key. Thanks to the session token configuration values are stored per user.

Some configuration values are plain numbers and I would like to have something like this: (Note that this is TypeScript)

Config.Get<number>("Value").then( x => this.Number= x);
Config.Set("Value", this.Number);

Instead of this:

Config.Get<{ x : number }>("Value").then( x => this.Number = x.x);
Config.Set("Value", { x: this.Number });

Thanks

Rafael
  • 2,642
  • 2
  • 24
  • 30
  • Possible duplicate of [What is the minimum valid JSON?](http://stackoverflow.com/questions/18419428/what-is-the-minimum-valid-json) – William Jan 21 '16 at 18:53
  • That question would answer if a single number is a valid JSON in which the answer is that "Is a valid JSON value, not a valid JSON file acording to RFC 4627", this questions asks if its posible to send a single number as JSON content. Since JSON.stringify allows single numbers, this would seem as viable – Rafael Jan 21 '16 at 19:00

0 Answers0