Stored Transformation

Stored transformation detail

Inspect version history, edit inputs, and save a new version without overwriting prior records.

Transformation ID segittur-hotel-pid-object-from-ngsi-building-2
Selected Version v6
Versions 6
Updated 2026-04-23T15:38:06.522837+00:00
Version 6 Version 5 Version 4 Version 3 Version 2 Version 1
Target Stored target schema Switch between manual editing, a persisted schema, and an internal schema, then validate or translate with the selected target schema.
Result Generated jq filter
def v($k): .[$k].value // null;
def trim:
  gsub("^\\s+|\\s+$"; "");
def clean_text:
  tostring
  | gsub("\\s+"; " ")
  | trim;
def gql_line($key; $value):
  if $value == null or $value == "" then
    ""
  else
    "            " + $key + " : " + ($value | @json) + "\n"
  end;
def province_from_postal_code($cp):
  if $cp | startswith("28") then "Madrid" else null end;
def ac_from_postal_code($cp):
  if $cp | startswith("28") then "Comunidad de Madrid" else null end;
def parsed_address:
  (v("address")) as $a
  | if ($a == null) or (($a | type) != "string") or (($a | clean_text) == "") then
      null
    else
      ($a | clean_text | gsub("\\.$"; "")) as $raw
      | if ($raw | test("\\b\\d{5}\\b")) then
          ($raw
           | capture("^(?<streetAddress>.*?)[,.;]?\\s*(?<postalCode>\\d{5})\\s+(?<municipality>[^,.;]+)")) as $m
          | {
              streetAddress: ($m.streetAddress | clean_text | gsub("[,.;]$"; "")),
              postalCode: $m.postalCode,
              municipality: ($m.municipality | clean_text),
              province: province_from_postal_code($m.postalCode),
              autonomousCommunity: ac_from_postal_code($m.postalCode),
              country: "España"
            }
          | with_entries(select(.value != null and .value != ""))
        else
          {
            streetAddress: $raw,
            country: "España"
          }
        end
    end;
def parsed_coords:
  (.location.value.coordinates // null) as $c
  | if ($c | type) == "array" and ($c | length) >= 2 and ($c[0] | type) == "number" and ($c[1] | type) == "number" then
      {long: $c[0], lat: $c[1]}
    else
      {}
    end;
(v("description")) as $desc
| (parsed_address) as $addr
| (parsed_coords) as $coords
| ((($addr // {}) + $coords)) as $loc
| {
    query:
      "mutation nuevo_hotel {\n" +
      "  createHotel(\n" +
      "    dti: \"pamplonairuna\"\n" +
      "    input: {\n" +
      "      object: \n" +
      "      {\n" +
      "        name : {\n" +
      "          value : " + (($desc // "Hotel PID") | @json) + "\n" +
      "          lang : \"es\"\n" +
      "        }\n" +
      (if $desc != null then
         "        hasDescription : {\n" +
         "          object : {\n" +
         "            shortDescription : {\n" +
         "              value : " + ($desc | @json) + "\n" +
         "              lang : \"es\"\n" +
         "            }\n" +
         "          }\n" +
         "        }\n"
       else
         ""
       end) +
      (if ($loc | length) > 0 then
         "        hasLocation : {\n" +
         "          object : {\n" +
         (gql_line("streetAddress"; $loc.streetAddress)) +
         (gql_line("postalCode"; $loc.postalCode)) +
         (gql_line("municipality"; $loc.municipality)) +
         (gql_line("province"; $loc.province)) +
         (gql_line("autonomousCommunity"; $loc.autonomousCommunity)) +
         (gql_line("country"; $loc.country)) +
         (gql_line("long"; $loc.long)) +
         (gql_line("lat"; $loc.lat)) +
         "          }\n" +
         "        }\n"
       else
         ""
       end) +
      "      }\n" +
      "    }\n" +
      "  ) {\n" +
      "    uri\n" +
      "    dtiName\n" +
      "    name {\n" +
      "      value\n" +
      "      lang\n" +
      "    }\n" +
      "  }\n" +
      "}",
    operationName: "nuevo_hotel"
  }
Output Transformed output
{
  "operationName": "nuevo_hotel",
  "query": "mutation nuevo_hotel {\n  createHotel(\n    dti: \"pamplonairuna\"\n    input: {\n      object: \n      {\n        name : {\n          value : \"Aparthotel TH Las Rozas\"\n          lang : \"es\"\n        }\n        hasDescription : {\n          object : {\n            shortDescription : {\n              value : \"Aparthotel TH Las Rozas\"\n              lang : \"es\"\n            }\n          }\n        }\n        hasLocation : {\n          object : {\n            streetAddress : \"Camino Viejo de Madrid, 38\"\n            postalCode : \"28230\"\n            municipality : \"Las Rozas\"\n            province : \"Madrid\"\n            autonomousCommunity : \"Comunidad de Madrid\"\n            country : \"Espa\u00f1a\"\n            long : -3.8565638\n            lat : 40.4845294\n          }\n        }\n      }\n    }\n  ) {\n    uri\n    dtiName\n    name {\n      value\n      lang\n    }\n  }\n}"
}