Can I declare a function field in Ada JSON?

Is it possible, with Ada, to implement the following JSON containing a function declaration x: integer (float(x))?

Example_JSON = "Integer": lambda x: integer (float(x))}

If so, how? I've tried to find a method in GNATCOLL.JSON without success.


Solution 1:

It is impossible because a JSON value, according to RFC 8259 can only be one of the following:

  • null
  • true
  • false
  • object
  • array
  • number
  • string

You can put the function's source code into a string, and then parse that string at the receiving end, e.g. {"integer": "lambda x: integer(float(x))"}, but there's no direct way for a function to be a value in an object.