CCD-102 practice question 4 of 30

A developer needs to update the package.json file so that it points to the hock file for a cartridge, using the hooks keyword. Which snippets work correctly when added to the file?:

Full set: 206 questions
Answer options
A: { “hooks”: “./cartridge/scripts/hooks.json” } Correct answer
B: { “hooks”: “./scripts/hooks.json” }
C: { hooks: “./cartridge/scripts/hooks.json” }
D: { hooks: ./scripts/hooks.json }
Correct Answer:
A. { “hooks”: “./cartridge/scripts/hooks.json” }
Explanation

To register hooks in a Salesforce B2C Commerce cartridge, the package.json file must be updated. This file requires strict JSON syntax, meaning both keys and string values must be enclosed in double quotes. The hooks property points to the hook definition file. According to official Salesforce documentation, the value for the hooks key is a relative path from the cartridge's root directory (where package.json is located) to the hooks.json file. The standard location for this file is within the cartridge/scripts directory. Therefore, the correct path is ./cartridge/scripts/hooks.json. Option A is the only choice that uses both valid JSON syntax and the correct conventional path.

References

Salesforce B2C Commerce Developer Documentation

"Extend B2C Commerce with Hooks": This official guide specifies the method for registering hooks. It provides a direct example: "To register a hook

you add a hooks property to your cartridge’s package.json file. The value of the property is a path to a hook definition file

relative to the cartridge’s root directory. For example: { "hooks": "./cartridge/scripts/hooks.json" }". This confirms the syntax and path in option A. (Reference available in the B2C Commerce Infocenter).

JSON Standard (ECMA-404): The official JSON standard specifies that object keys (names) must be strings enclosed in double quotes. This rule invalidates options C and D. (See Section 4

"Objects").

Scroll to Top