fixed json encode for single record.
refactored, bugfixed