SyntaxError: Unexpected token < in JSON at position 0


Im getting this error on this function

.subscribe((res) => {
        this.list = res.json();
    }, (err) => {

I left request first parameter a empty string, what should i give here, firebase address like this?, im getting same error


The first parameter for this.http.request("") should be the URL you are trying to get data from.
As you are trying to convert the response you receive to JSON - you need to provide an URL which can return JSON response. ( doesn’t return a JSON response)

try out
.subscribe((res) => {console.log(res.json())})


what is json placeholder, and the whole address i mean im unable to understand my data is at firebase how can i get data from another url like you said jsonplaceholder.typicode


@yoyodj As @sankar_gopalan mentioned, the first parameter should be a URL which returns JSON data. Let’s say that your Firebase URL is, then you can’t use just because it doesn’t return JSON - it returns HTML, which means that you have to specify that you want JSON data: Now the returned data is in JSON format but it returns the whole content of the Firebase instance, which you probably don’t want. Let’s say that you want to retrieve all posts which are stored in posts under the Firebase root, then your URL should be Also don’t forget to use a real Firebase URL, i.e. xyz should be the name of the Firebase instance that you’re trying to get data from, which means that you should replace it with the Firebase data URL of your Firebase account.

    // Call map on the response observable to get the parsed object.
    .map((res) => res.json())
    // Subscribe to the observable to get the parsed object and use it.
    .subscribe((posts) => {
	    this.list = posts;
    }, (err) => {


Suppose I want to get title:“fjslk” of this KF6dIZnUliIVtNykDEN(what is it called btw) then my url would be like this

.map((res) => res.json()).subscribe((res) => {console.log(res.json)}

as response i got Object {-KF6dIZnUliIVtNykDEN: Object} at the console, also adding this line .map((res) => res.json()) giving me error .map is not defined,
how can i do this


@yoyodj Sorry, I forgot to mention that you have to import it, add this to your imports:

import 'rxjs/add/operator/map';

The string KF6dIZnUliIVtNykDEN is a Firebase unique ID - it’s generated automatically when you add new data to a Firebase path using push().

Here is a working plunker demo, you just have to add your Firebase data URL in home.ts.


Oh yes can i build facebook like application in this like if i create post(it will be object in the list with unique id) and when somebody comments it should make sure belong to that post(i think with unique id its possible, can i retrieve id)


Thanks man! This post got me through my troubles, getting correctly formatted JSON data now :wink:


Hi @iignatov ,

Could you help me how to get the token ??
I am using service.
My result after succesfull login was like this…

Object {lastLogin: 1463742055662, created: 1456890510000, name: "personal", ___class: "Users", user-token: "7652C01C-7343-F9AE-FF15-DD7E0427A800"…}

Please look at my console.log at my user_service.js.
I can console.log email or objectId but fail for user-token.
My problem is how to get the user-token and save it to localstorage so i can use it for another purpose??
my user_service.js

import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Headers, RequestOptions} from 'angular2/http';
import {Observable}     from 'rxjs/Observable';
import {BackendService} from './backend_service';
import {Storage, LocalStorage, Events} from 'ionic-angular';
import 'rxjs/Rx';

export class UserService {

    static get parameters() {
        return [[Http], [BackendService], [Events]];

    constructor(http, backendService, events) {
        this.http = http;
        this.backendService = backendService; = events;
        this.user = {}; = new Storage(LocalStorage);
        this.HAS_LOGGED_IN = 'hasLoggedIn';
        this.Backend_Login_Url = backendService.BackendLoginUrl
        this.Backend_Register_Url = backendService.BackendRegisterUrl
        this.Backend_Logout_Url = backendService.BackendLogoutUrl
        this.Backend_Header = backendService.BackendHeader

        let body = JSON.stringify({ login:, password: userData.password });
        let headers = new Headers(this.Backend_Header);
        let options = new RequestOptions({ headers: headers });
        return, body, options)
            .map((res) => {
               let data = res.json();
               console.log(' at user_service',; // result :
               console.log('data.objectId at user_service', data.objectId); // result C8FE36A2-9396-13C5-FF9C-8F8EF7F07900
               console.log('data.user-token at user_service', data.user-token); // result Reference error : Token is not defined
    'userStorage', JSON.stringify(data)); // result : success
              return data;

Thks in advance.


You can’t use ‘-’ in variable name.

How to handle nested JSON

@sciu You have to use data['user-token'], as @xr0master suggested.


It works…

Thks for @xr0master suggestion
and thks @iignatov for ur reply…