walkerline117
8 years agoContributor
Show only partial body of a json
Hi
If I have below json body, How would I hide certain fields inside the json body and only show partial of it.
Input:
{
"apiVersion": "1.0",
"noOfRecords": 41607,
"params": {
...
- 8 years ago
There’s a
filter()method on objects that you can use to filter properties in objects. For example, to retain only the ‘q’ and ‘qt’ properties in the$paramsobject, you can use the following expression:$params.filter((value, key) => ['q', 'qt'].indexOf(key) != -1)Since the property names are user-supplied, you’d want to replace the
['q', 'qt']array literal with array from the user. For example, if the names were in a JSON-encoded array in the “field” pipeline parameter, you would use:$params.filter((value, key) => JSON.parse(_fields).indexOf(key) != -1)