Lesson 10: JSON and Dates

Intermediate

Real-world programs often exchange data as JSON and work with dates and times. Phograph provides built-in nodes for both.

Parsing and encoding JSON

The json-parse node takes a JSON string and produces a Phograph value — a number, string, list, or dictionary depending on the content. The json-encode node does the reverse: it takes any Phograph value and produces a JSON string.

  constant '{"name":"Ada","age":36}' --> json-parse --> get "name" --> log
                                                         outputs: "Ada"
  dict ["x", 10, "y", 20] --> json-encode --> log
                                outputs: '{"x":10,"y":20}'

Round-tripping

You can chain the two nodes to verify that encoding and parsing are inverses:

  value --> json-encode --> json-parse --> equal? --> log
    \---------------------------------------/          outputs: true

Date primitives

Phograph includes several date and time nodes:

  date-create(2026, 3, 5, 9, 0, 0) --> date-add(hours 2) --> date-components
                                                                outputs: hour = 11

Time helpers

Duration values are created with helper nodes that convert human-friendly units into an internal duration type:

  seconds 90      -- 90 seconds
  minutes 5       -- 5 minutes (300 seconds)
  hours 2         -- 2 hours
  days 7          -- 7 days

These plug directly into date-add and can be compared with date-diff results.

  date-now --> date-add(days 30) --> log   -- prints a date 30 days from now

What you learned