how do we calculate the current density given the magnetic field?

The magnetic field does NOT depend upon the local current density. The magnetic field depends upon the current density in the surrounding environment, wherever current is flowing.

Read about the Biot-Savart law for more information.