Quantcast
Channel: How to form correct JQ Expression to get exact output data from JSON file? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to form correct JQ Expression to get exact output data from JSON file?

$
0
0

I am using JQ Play.

Here is my JSON Data -

{"body": {"name": "DATATYPES","primarykey": ["db_number"    ],"members": [      {"name": "db_number","type": "NUMBER"      },      {"name": "db_date","type": "DATE"      },      {"name": "db_timestamp","type": "TIMESTAMP(6)"      },      {"name": "db_timestamp_with_local_time_zone","type": "TIMESTAMP(6) WITH LOCAL TIME ZONE"      },      {"name": "db_char","type": "CHAR"      },      {"name": "db_float","type": "FLOAT"      },      {"name": "db_nchar","type": "NCHAR"      },      {"name": "db_nvarchar2","type": "NVARCHAR2"      },      {"name": "db_varchar2","type": "VARCHAR2"      },      {"name": "db_binary_float","type": "BINARY_FLOAT"      },      {"name": "db_binary_double","type": "BINARY_DOUBLE"      },      {"name": "db_timestamp_with_time_zone","type": "TIMESTAMP(6) WITH TIME ZONE"      },      {"name": "db_interval_year_to_month","type": "INTERVAL YEAR(2) TO MONTH"      },      {"name": "db_interval_day_to_second","type": "INTERVAL DAY(2) TO SECOND(6)"      },      {"name": "db_long","type": "LONG"      },      {"name": "db_blob","type": "BLOB"      },      {"name": "db_clob","type": "CLOB"      },      {"name": "db_boolean","type": "CHAR"      }    ],"links": [      {"rel": "collection","href": "https://tdcvm28s16.bcone.com:7002/ords/testords/metadata-catalog/","mediaType": "application/json"      },      {"rel": "canonical","href": "https://tdcvm28s16.bcone.com:7002/ords/testords/metadata-catalog/datatypes/","mediaType": "application/json"      },      {"rel": "alternate","href": "https://tdcvm28s16.bcone.com:7002/ords/testords/open-api-catalog/datatypes/","mediaType": "application/openapi+json"      },      {"rel": "describes","href": "https://tdcvm28s16.bcone.com:7002/ords/testords/datatypes/"      }    ]  }}

My JQ -

{parameters: (.body.primarykey[] | {(.): ""}), body: (.body.members | map({(.name): .type |ascii_downcase}) | add)}

Output -

{"parameters": {"db_number": ""  },"body": {"db_number": "number","db_date": "date","db_timestamp": "timestamp(6)","db_timestamp_with_local_time_zone": "timestamp(6) with local time zone","db_char": "char","db_float": "float","db_nchar": "nchar","db_nvarchar2": "nvarchar2","db_varchar2": "varchar2","db_binary_float": "binary_float","db_binary_double": "binary_double","db_timestamp_with_time_zone": "timestamp(6) with time zone","db_interval_year_to_month": "interval year(2) to month","db_interval_day_to_second": "interval day(2) to second(6)","db_long": "long","db_blob": "blob","db_clob": "clob","db_boolean": "char"  }}

Here, my requirement is - I want to remove record / field from output body:{} which is having same name as primarykey.

So I am not able to form such JQ that will not fetch matching record with primarykey inside body.

My expected output is -

{"parameters": {"db_number": ""  },"body": {"db_date": "date","db_timestamp": "timestamp(6)","db_timestamp_with_local_time_zone": "timestamp(6) with local time zone","db_char": "char","db_float": "float","db_nchar": "nchar","db_nvarchar2": "nvarchar2","db_varchar2": "varchar2","db_binary_float": "binary_float","db_binary_double": "binary_double","db_timestamp_with_time_zone": "timestamp(6) with time zone","db_interval_year_to_month": "interval year(2) to month","db_interval_day_to_second": "interval day(2) to second(6)","db_long": "long","db_blob": "blob","db_clob": "clob","db_boolean": "char"  }}

Please help me with correct JQ that will work in jqplay.org


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>