に is not always only used to mark an object. It is helpful to also further distinguish between between a "direct object" (usually marked with を) and an "indirect object" (usually marked with に or と).
used as a subject mark
Mutsuko Endo Hudson in English Grammar for Students of Japanese describes a subject as:
In a sentence describing an action, the person or thing that performs the action is called the subject. When you wish to find the subject of the sentence, look for the verb first; then ask, who? or what? before the verb. The answer will be the subject.
In many Japanese clauses, you'll need to infer the subject, because it isn't explicitly stated in the text or speech alone.
に has several functions, and its function depends on the particular verb that に is used with.
Makino and Tsutsui in A Dictionary of Basic Japanese Grammar lists the elementary and most common usages of に:
- point of time at which something takes place
- indirect object marker
- agent or source in passive, causative and other receiving constructions
- surface marker
- purpose when someone moves from one place to another
- location where someone or something exists
- place toward which someone or something moves
However, don't be misled into thinking that this list is exhaustive. に appears in many other patterns and its usage will differ from pattern to pattern.
Group Jamassy in A Handbook of Japanese Grammar Patterns for Teachers and Learners lists about 70 different grammar patterns using に and a particular verb or inflection of a verb. Some of those に patterns have a component marked by に, where that component also is, coincidentally, the subject. But some of those に patterns do not have a component that is coincidentally also the subject.
For example, on page 460 of A Handbook of Japanese Grammar Patterns for Teachers and Learners, in the pattern Nにかかっては, they show this example sentence and its English translation:
- 彼女にかかってはいつもしらないうちにイエスと言わされてしまう。/ She always makes me say yes without my noticing it.
Here, 彼女 (she) is marked by に, but 彼女 is also the subject because "she" is performing the action.
Breaking it up for clarity and understanding:
彼女 (she)
にかかっては (no one can match her behavior)
いつも (always)
しらないうちに (without noticing)
しらない (to not notice)
うちに (at a time within)
イエスと (say yes)
言わされてしまう (force me to say, regrettably)
Group Jamassy's explanation of にかかっては, also from page 460:
With a noun expressing a person or behavior, にかかっては indicates the person or the behavior, followed by an expression to mean that no one can match him/her or his/her behavior including what s/he said.