hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/extract/json.json
{
"name": "hydra.core.extract.json",
"metadata": {"description": "Utilities for extracting values from JSON objects", "comments": [], "seeAlso": [], "provisions": []},
"dependencies": [
{"module": "hydra.core.json.model"},
{"module": "hydra.core.json.writer"},
{"module": "hydra.core.lib.eithers"},
{"module": "hydra.core.lib.maps"},
{"module": "hydra.core.lib.optionals"},
{"module": "hydra.core.lib.strings"}],
"definitions": [
{
"term": {
"name": "hydra.core.extract.json.expectArray",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.json.model.Value"}, "isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"list": {"variable": "hydra.core.json.model.Value"}}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "value",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.json.model.Value",
"default": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"left": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat2"},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "expected "}}}},
"argument": {"literal": {"string": "JSON array"}}}}}},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": " but found "}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.showValue"}, "argument": {"variable": "value"}}}}}}}}},
"type": {"literal": "string"}}},
"type": {"list": {"variable": "hydra.core.json.model.Value"}}}},
"cases": [
{
"name": "array",
"handler": {
"lambda": {
"parameter": "els",
"domain": {"list": {"variable": "hydra.core.json.model.Value"}},
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"either": {"right": {"variable": "els"}}}, "type": {"literal": "string"}}},
"type": {"list": {"variable": "hydra.core.json.model.Value"}}}}}}}]}},
"argument": {"variable": "value"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Extract an array from a JSON value, failing if the value is not an array"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.expectNumber",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.json.model.Value"}, "isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"literal": "decimal"}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "value",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.json.model.Value",
"default": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"left": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat2"},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "expected "}}}},
"argument": {"literal": {"string": "JSON number"}}}}}},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": " but found "}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.showValue"}, "argument": {"variable": "value"}}}}}}}}},
"type": {"literal": "string"}}},
"type": {"literal": "decimal"}}},
"cases": [
{
"name": "number",
"handler": {
"lambda": {
"parameter": "d",
"domain": {"literal": "decimal"},
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"either": {"right": {"variable": "d"}}}, "type": {"literal": "string"}}},
"type": {"literal": "decimal"}}}}}}]}},
"argument": {"variable": "value"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Extract a number from a JSON value, failing if the value is not a number"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.expectObject",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.json.model.Value"}, "isLazy": false}],
"result": {
"type": {
"either": {
"left": {"literal": "string"},
"right": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "value",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.json.model.Value",
"default": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"left": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat2"},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "expected "}}}},
"argument": {"literal": {"string": "JSON object"}}}}}},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": " but found "}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.showValue"}, "argument": {"variable": "value"}}}}}}}}},
"type": {"literal": "string"}}},
"type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}}}},
"cases": [
{
"name": "object",
"handler": {
"lambda": {
"parameter": "m",
"domain": {"list": {"pair": {"first": {"literal": "string"}, "second": {"variable": "hydra.core.json.model.Value"}}}},
"body": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"right": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.maps.fromList"}, "type": {"literal": "string"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "m"}}}}},
"type": {"literal": "string"}}},
"type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}}}}}}}]}},
"argument": {"variable": "value"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {
"string": "Extract an object from a JSON value as a name-keyed map, failing if the value is not an object. Field order is not preserved; lookups are by name."}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.expectString",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.json.model.Value"}, "isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"literal": "string"}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "value",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.json.model.Value",
"default": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"left": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat2"},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "expected "}}}},
"argument": {"literal": {"string": "JSON string"}}}}}},
"argument": {
"application": {
"function": {
"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": " but found "}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.showValue"}, "argument": {"variable": "value"}}}}}}}}},
"type": {"literal": "string"}}},
"type": {"literal": "string"}}},
"cases": [
{
"name": "string",
"handler": {
"lambda": {
"parameter": "s",
"domain": {"literal": "string"},
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"either": {"right": {"variable": "s"}}}, "type": {"literal": "string"}}},
"type": {"literal": "string"}}}}}}]}},
"argument": {"variable": "value"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Extract a string from a JSON value, failing if the value is not a string"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.opt",
"signature": {
"typeParameters": [{"name": "t0", "constraints": [{"simple": "ordering"}]}, {"name": "t1", "constraints": []}],
"parameters": [
{"name": "arg0", "type": {"variable": "t0"}, "isLazy": false},
{"name": "arg1", "type": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "t1"}}}, "isLazy": false}],
"result": {"type": {"optional": {"variable": "t1"}}}},
"body": {
"typeLambda": {
"parameter": "t0",
"body": {
"typeLambda": {
"parameter": "t1",
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"variable": "t0"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "t1"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.maps.lookup"}, "type": {"variable": "t0"}}},
"type": {"variable": "t1"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}}}},
"annotation": {
"map": [{"key": {"variable": "description"}, "value": {"literal": {"string": "Look up an optional field in a JSON object"}}}]}}}}}}}}},
{
"term": {
"name": "hydra.core.extract.json.optArray",
"signature": {
"typeParameters": [{"name": "t0", "constraints": [{"simple": "ordering"}]}],
"parameters": [
{"name": "arg0", "type": {"variable": "t0"}, "isLazy": false},
{
"name": "arg1",
"type": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"isLazy": false}],
"result": {
"type": {
"either": {"left": {"literal": "string"}, "right": {"optional": {"list": {"variable": "hydra.core.json.model.Value"}}}}}}},
"body": {
"typeLambda": {
"parameter": "t0",
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"variable": "t0"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.optionals.match"}, "type": {"variable": "hydra.core.json.model.Value"}}},
"type": {
"either": {"left": {"literal": "string"}, "right": {"optional": {"list": {"variable": "hydra.core.json.model.Value"}}}}}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.extract.json.opt"}, "type": {"variable": "t0"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"right": {"typeApplication": {"body": {"optional": null}, "type": {"list": {"variable": "hydra.core.json.model.Value"}}}}}},
"type": {"literal": "string"}}},
"type": {"optional": {"list": {"variable": "hydra.core.json.model.Value"}}}}}}},
"argument": {
"lambda": {
"parameter": "a",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.eithers.map"}, "type": {"list": {"variable": "hydra.core.json.model.Value"}}}},
"type": {"optional": {"list": {"variable": "hydra.core.json.model.Value"}}}}},
"type": {"literal": "string"}}},
"argument": {
"lambda": {
"parameter": "x",
"domain": {"list": {"variable": "hydra.core.json.model.Value"}},
"body": {"optional": {"variable": "x"}}}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.expectArray"}, "argument": {"variable": "a"}}}}}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up an optional array field in a JSON object"}}}]}}}}}}},
{
"term": {
"name": "hydra.core.extract.json.optString",
"signature": {
"typeParameters": [{"name": "t0", "constraints": [{"simple": "ordering"}]}],
"parameters": [
{"name": "arg0", "type": {"variable": "t0"}, "isLazy": false},
{
"name": "arg1",
"type": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"optional": {"literal": "string"}}}}}},
"body": {
"typeLambda": {
"parameter": "t0",
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"variable": "t0"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"variable": "t0"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.optionals.match"}, "type": {"variable": "hydra.core.json.model.Value"}}},
"type": {"either": {"left": {"literal": "string"}, "right": {"optional": {"literal": "string"}}}}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.extract.json.opt"}, "type": {"variable": "t0"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {"either": {"right": {"typeApplication": {"body": {"optional": null}, "type": {"literal": "string"}}}}},
"type": {"literal": "string"}}},
"type": {"optional": {"literal": "string"}}}}}},
"argument": {
"lambda": {
"parameter": "s",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.eithers.map"}, "type": {"literal": "string"}}},
"type": {"optional": {"literal": "string"}}}},
"type": {"literal": "string"}}},
"argument": {"lambda": {"parameter": "x", "domain": {"literal": "string"}, "body": {"optional": {"variable": "x"}}}}}},
"argument": {"application": {"function": {"variable": "hydra.core.extract.json.expectString"}, "argument": {"variable": "s"}}}}}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up an optional string field in a JSON object"}}}]}}}}}}},
{
"term": {
"name": "hydra.core.extract.json.require",
"signature": {
"typeParameters": [{"name": "t0", "constraints": []}],
"parameters": [
{"name": "arg0", "type": {"literal": "string"}, "isLazy": false},
{"name": "arg1", "type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "t0"}}}, "isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"variable": "t0"}}}}},
"body": {
"typeLambda": {
"parameter": "t0",
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"literal": "string"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"literal": "string"}, "values": {"variable": "t0"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.optionals.match"}, "type": {"variable": "t0"}}},
"type": {"either": {"left": {"literal": "string"}, "right": {"variable": "t0"}}}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.maps.lookup"}, "type": {"literal": "string"}}},
"type": {"variable": "t0"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {
"either": {
"left": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "required attribute "}},
{
"application": {
"function": {"variable": "hydra.core.extract.json.showValue"},
"argument": {"inject": {"typeName": "hydra.core.json.model.Value", "field": {"name": "string", "term": {"variable": "fname"}}}}}},
{"literal": {"string": " not found"}}]}}}}},
"type": {"literal": "string"}}},
"type": {"variable": "t0"}}}}},
"argument": {
"lambda": {
"parameter": "value",
"domain": {"variable": "t0"},
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"either": {"right": {"variable": "value"}}}, "type": {"literal": "string"}}},
"type": {"variable": "t0"}}}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up a required field in a JSON object, failing if not found"}}}]}}}}}}},
{
"term": {
"name": "hydra.core.extract.json.requireArray",
"signature": {
"typeParameters": [],
"parameters": [
{"name": "arg0", "type": {"literal": "string"}, "isLazy": false},
{
"name": "arg1",
"type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"list": {"variable": "hydra.core.json.model.Value"}}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"literal": "string"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.eithers.bind"}, "type": {"literal": "string"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"type": {"list": {"variable": "hydra.core.json.model.Value"}}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {"body": {"variable": "hydra.core.extract.json.require"}, "type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {"variable": "hydra.core.extract.json.expectArray"}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up a required array field in a JSON object"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.requireNumber",
"signature": {
"typeParameters": [],
"parameters": [
{"name": "arg0", "type": {"literal": "string"}, "isLazy": false},
{
"name": "arg1",
"type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"literal": "decimal"}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"literal": "string"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.eithers.bind"}, "type": {"literal": "string"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"type": {"literal": "decimal"}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {"body": {"variable": "hydra.core.extract.json.require"}, "type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {"variable": "hydra.core.extract.json.expectNumber"}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up a required number field in a JSON object"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.requireString",
"signature": {
"typeParameters": [],
"parameters": [
{"name": "arg0", "type": {"literal": "string"}, "isLazy": false},
{
"name": "arg1",
"type": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"literal": "string"}}}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "fname",
"domain": {"literal": "string"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"map": {"keys": {"literal": "string"}, "values": {"variable": "hydra.core.json.model.Value"}}},
"body": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.eithers.bind"}, "type": {"literal": "string"}}},
"type": {"variable": "hydra.core.json.model.Value"}}},
"type": {"literal": "string"}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {"body": {"variable": "hydra.core.extract.json.require"}, "type": {"variable": "hydra.core.json.model.Value"}}},
"argument": {"variable": "fname"}}},
"argument": {"variable": "m"}}}}},
"argument": {"variable": "hydra.core.extract.json.expectString"}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Look up a required string field in a JSON object"}}}]}}}}},
{
"term": {
"name": "hydra.core.extract.json.showValue",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.json.model.Value"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "value",
"domain": {"variable": "hydra.core.json.model.Value"},
"body": {"application": {"function": {"variable": "hydra.core.json.writer.printJson"}, "argument": {"variable": "value"}}}}},
"annotation": {"map": [{"key": {"variable": "description"}, "value": {"literal": {"string": "Show a JSON value as a string"}}}]}}}}}]}