Some ECMWF data produced by the IFS is stored in GRIB with gridType=sh to indicate that the values are stored as spherical harmonic coefficients. 

The resolution of such data is identified by the triangular truncation number which specifies the number of coefficients retained in the infinite sum.  This number is stored in GRIB as the pentagonal resolution parameters, J, K and M:

ecCodes keycontentGRIB edition 1GRIB edition 2
JJ pentagonal resolution parameterSection 2 Octets 7-8Section 3 Octets 15-18
KK pentagonal resolution parameterSection 2 Octets 9-10Section 3 Octets 19-22
MM pentagonal resolution parameterSection 2 Octets 11-12Section 3 Octets 23-26

The pentagonal representation of resolution is general and the triangular representation used by ECMWF is a specific case with  M = J = K.   The truncation number, and hence the resolution of the data, can be obtained by querying the value of any one of these keys.  Most usually, the value of J - or its alias pentagonalResolutionParameterJ - is used:

% grib_get -p J t1000.grib
1279

In this case, the value of J=1279 indicates the triangular truncation used is T1279.

How is the resolution of the spherical harmonic data related to the grid resolution ?

It is not possible to relate the resolution of the spherical harmonic data directly to the resolution of the corresponding grid as this depends on the specific relationship between the spectral representation and the Gaussian grid used by the IFS.  Three different relationships have been used by ECMWF over the years.  For a triangular truncation of T, the corresponding Gaussian grid resolutions are:

RelationshipGaussian grid resolution
linearN = (T + 1) / 2
quadraticN = 3 (T+1) / 4
cubicN = T + 1

where N corresponds to the number of latitude lines between the poles and the equator.  However, to determine which relationship was used when the data were produced requires interrogation of a corresponding grid point field.

See also: