Below is the input JSON:
{"sn": "fdd","sc": [ {"pn": "di","pv": {"val": "26","com": "=" },"fix": "Hello","tp": "String" }, {"pn": "di2","pv": {"val": "28","com": "=" },"fix": "Hello2","tp": "String" } ]}
Below is the JQ Command I have tried which is generating identical objects:
def getWhereVal(input):[input.sc[]] | unique;def getPreVal(input):input.sc[].fix;. as $input | getPreVal($input) as $preVal | getWhereVal($input)
I am getting below output from above JQ command:
[ {"pn": "di","pv": {"val": "26","com": "=" },"fix": "Hello","tp": "String" }, {"pn": "di2","pv": {"val": "28","com": "=" },"fix": "Hello2","tp": "String" }][ {"pn": "di","pv": {"val": "26","com": "=" },"fix": "Hello","tp": "String" }, {"pn": "di2","pv": {"val": "28","com": "=" },"fix": "Hello2","tp": "String" }]
I aim to retrieve a distinct object from a set of identical objects, as illustrated below:
{"pn": "di","pv": {"val": "26","com": "=" },"fix": "Hello","tp": "String" }, {"pn": "di2","pv": {"val": "28","com": "=" },"fix": "Hello2","tp": "String" }
Can someone please help me to get desired output, I am not able to get result using unique function.