Docs
When to use this JSON
When you need shopping-cart JSON with products, quantities, totals, and discount math — for cart UI, checkout flow, or order-confirmation screens.
Copy-ready shopping-cart JSON with products, totals, discount math,
and per-user carts. Add, update, and delete requests. Live REST
endpoint at /carts.
Carts
Get all carts
fetch('https://jsonexamples.com/carts')
.then(res => res.json())
.then(console.log);
Show output
Get a single cart
fetch('https://jsonexamples.com/carts/1')
.then(res => res.json())
.then(console.log);
Show output
Get carts of a user
// getting carts of user with id 5
fetch('https://jsonexamples.com/carts/user/5')
.then(res => res.json())
.then(console.log);
Show output
Add a new cart
Adding a new cart will not add it into the server.
It will simulate a POST request and will return the new created
cart with a new id
You can provide a userId and array of products as objects,
containing productId & quantity
fetch('https://jsonexamples.com/carts/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
userId: 1,
products: [
{
id: 1,
quantity: 1,
},
{
id: 50,
quantity: 2,
},
]
})
})
.then(res => res.json())
.then(console.log);
Show output
Update a cart
Updating a cart will not update it into the server.
Pass "merge: true" to include old products when updating
It will simulate a PUT/PATCH request and will return updated cart
with modified data
You can provide a userId and array of products as objects,
containing productId & quantity
/* adding products in cart with id 1 */
fetch('https://jsonexamples.com/carts/1', {
method: 'PUT', /* or PATCH */
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
merge: true, // this will include existing products in the cart
products: [
{
id: 1,
quantity: 1,
},
]
})
})
.then(res => res.json())
.then(console.log);
Show output
Delete a cart
Deleting a cart will not delete it into the server.
It will simulate a DELETE request and will return deleted cart
with "isDeleted" & "deletedOn" keys
fetch('https://jsonexamples.com/carts/1', {
method: 'DELETE',
})
.then(res => res.json())
.then(console.log);
Show output