Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7731] Android: Objects passed to "Ti.API.debug" should be printed as JSON

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsparity
ReporterIvan Skugor
AssigneeJan Vennemann
Created2012-01-23T08:36:29.000+0000
Updated2020-01-08T18:31:04.000+0000

Description

Problem

Currently, "Ti.API.debug" prints object in a way it calls object's "toString" function. That way we get string "[object Object]" for native objects. But that information is useless for debugging purposes. It would be much better if objects were printed as JSON.

Test case

var myObject = { prop: 42 };

Ti.API.debug(myObject);

Output

Console output is "[object Object]", while it should be printing: "{ prop: 42 }", or even better (to avoid ambiguity): myObject: "{ prop: 42 }".

Workaround

A workaround is to use "JSON.stringify" prior to calling "Ti.API.debug": Ti.API.debug(JSON.stringify(myObject));

Comments

  1. Arthur Evans 2012-04-18

    On iOS and Mobile Web, the object's properties are logged, so this is a parity issue. Logging is slightly different by platform. Mobile Web logs: { "prop": 42 } While iPhone logs: { prop = 42; } But both are eminently usable.
  2. Ivan Skugor 2012-04-19

    Usable yes, but JSON no. :) IMHO, JSON format should be preferred for JS object representation.
  3. Ivan Skugor 2012-04-27

  4. Chris Barber 2016-08-24

    Confirmed. This is still an issue as of Titanium SDK 6.1.0 master branch.

JSON Source