Sort a JSON Catalog and Re-serialize

Easy ⏱ 8 min 85% acceptance ★★★★★ 4.5
Write sort_catalog(raw) that parses a JSON array of products (each with name and price), sorts them by price ascending, and returns the re-serialized JSON string — the everyday parse → transform → dump cycle.

Examples

Example 1
Input
sort_catalog(json_text)  # [{"name": "b", "price": 5}, {"name": "a", "price": 2}]
Output
[{"name": "a", "price": 2}, {"name": "b", "price": 5}]
Explanation

Cheapest first after the round-trip.

Constraints

  • Sort on the price field.
  • Return a JSON string.

Topics

JSONparse-sort-dump

Companies

ShopifyBigCommerceFlipkart

Hints

Hint 1

sorted(data, key=lambda p: p['price']).

Hint 2

dumps the sorted list.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.