Remove non JSON values

In this example we will see how to remove non json values.

If your input looks like

{=
{"gender": "female", "name": {"title": "Miss", "first": "Fredrikke", "last": "Furseth"}, "location": {"street": {"number": 9975, "name": "Balchens gate"}, "city": "Fjellsrud", "state": "M\u00f8re og Romsdal", "country": "Norway", "postcode": "8270", "coordinates": {"latitude": "46.6152", "longitude": "59.8624"}, "timezone": {"offset": "-2:00", "description": "Mid-Atlantic"}}, "email": "fredrikke.furseth@example.com", "login": {"uuid": "5306f026-ea91-4f96-9ab0-8229252fc871", "username": "angryleopard250", "password": "rated", "salt": "NKh0JAuO", "md5": "45a26eaa0c8fc9861b29c2211c1636f2", "sha1": "5a5527b43338a219b95a2346dc8c244286b6aa9a", "sha256": "446795d9f362f9120c0ae9523cdfdfb1e5f61c8c8bd89d01a56a9443a48facfb"}, "dob": {"date": "1954-08-23T16:43:10.251Z", "age": 69}, "registered": {"date": "2013-08-21T11:49:36.862Z", "age": 10}, "phone": "31985401", "cell": "94426914", "id": {"name": "FN", "value": "23085412825"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/women\/13.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/women\/13.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/women\/13.jpg"}, "nat": "NO"}
test
{"gender": "female", "name": {"title": "Mademoiselle", "first": "Margrit", "last": "Sanchez"}, "location": {"street": {"number": 3656, "name": "Rue de L'Abb\u00e9-Roger-Derry"}, "city": "M\u00e4nnedorf", "state": "Neuch\u00e2tel", "country": "Switzerland", "postcode": 9084, "coordinates": {"latitude": "-78.2618", "longitude": "8.2599"}, "timezone": {"offset": "+6:00", "description": "Almaty, Dhaka, Colombo"}}, "email": "margrit.sanchez@example.com", "login": {"uuid": "74735e17-9364-4a56-af45-1fbec388e838", "username": "greenbutterfly897", "password": "throat", "salt": "DVrPIJAH", "md5": "d837977d8a8da07ec7e4c9e3fc87d012", "sha1": "7325bb30a9921828c6caa88cacd2ff1a9e332a30", "sha256": "1ff87666699c1efbd12f6ac1e5774b03e8ffa427fbc1bfa90db0253b8eb985f4"}, "dob": {"date": "1981-07-16T08:23:18.063Z", "age": 42}, "registered": {"date": "2003-07-23T17:44:35.902Z", "age": 20}, "phone": "078 295 70 38", "cell": "079 826 99 10", "id": {"name": "AVS", "value": "756.7360.9969.72"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/women\/87.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/women\/87.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/women\/87.jpg"}, "nat": "CH"}

{?
}

{"gender": "male", "name": {"title": "Mr", "first": "Fabio", "last": "Berden"}, "location": {"street": {"number": 1670, "name": "Kuppersweg"}, "city": "Geersdijk", "state": "Flevoland", "country": "Netherlands", "postcode": "4752 EK", "coordinates": {"latitude": "-51.2995", "longitude": "166.2318"}, "timezone": {"offset": "+5:30", "description": "Bombay, Calcutta, Madras, New Delhi"}}, "email": "fabio.berden@example.com", "login": {"uuid": "7cfd3044-d25c-43d0-af6b-e1d73667de8a", "username": "blackbear880", "password": "charlotte", "salt": "E5rwRznF", "md5": "ba3cb10d7412b20aebd036dfb0cc3cf5", "sha1": "93d3a46f1c54dc39f9d5735a4a1c2b3186925ea6", "sha256": "bd22abc4798b1eff04d9168dba5eb021d6427eeabad846506148b7463d205e2b"}, "dob": {"date": "1965-10-23T10:14:32.717Z", "age": 58}, "registered": {"date": "2003-02-25T05:58:56.678Z", "age": 20}, "phone": "(082) 7277281", "cell": "(06) 55254073", "id": {"name": "BSN", "value": "23564900"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/men\/72.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/men\/72.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/men\/72.jpg"}, "nat": "NL"}
hello

123

You can use jawk like:

jawk

To produce:

{"gender": "female", "name": {"title": "Miss", "first": "Fredrikke", "last": "Furseth"}, "location": {"street": {"number": 9975, "name": "Balchens gate"}, "city": "Fjellsrud", "state": "M\u00f8re og Romsdal", "country": "Norway", "postcode": "8270", "coordinates": {"latitude": "46.6152", "longitude": "59.8624"}, "timezone": {"offset": "-2:00", "description": "Mid-Atlantic"}}, "email": "fredrikke.furseth@example.com", "login": {"uuid": "5306f026-ea91-4f96-9ab0-8229252fc871", "username": "angryleopard250", "password": "rated", "salt": "NKh0JAuO", "md5": "45a26eaa0c8fc9861b29c2211c1636f2", "sha1": "5a5527b43338a219b95a2346dc8c244286b6aa9a", "sha256": "446795d9f362f9120c0ae9523cdfdfb1e5f61c8c8bd89d01a56a9443a48facfb"}, "dob": {"date": "1954-08-23T16:43:10.251Z", "age": 69}, "registered": {"date": "2013-08-21T11:49:36.862Z", "age": 10}, "phone": "31985401", "cell": "94426914", "id": {"name": "FN", "value": "23085412825"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/women\/13.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/women\/13.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/women\/13.jpg"}, "nat": "NO"}
{"gender": "female", "name": {"title": "Mademoiselle", "first": "Margrit", "last": "Sanchez"}, "location": {"street": {"number": 3656, "name": "Rue de L'Abb\u00e9-Roger-Derry"}, "city": "M\u00e4nnedorf", "state": "Neuch\u00e2tel", "country": "Switzerland", "postcode": 9084, "coordinates": {"latitude": "-78.2618", "longitude": "8.2599"}, "timezone": {"offset": "+6:00", "description": "Almaty, Dhaka, Colombo"}}, "email": "margrit.sanchez@example.com", "login": {"uuid": "74735e17-9364-4a56-af45-1fbec388e838", "username": "greenbutterfly897", "password": "throat", "salt": "DVrPIJAH", "md5": "d837977d8a8da07ec7e4c9e3fc87d012", "sha1": "7325bb30a9921828c6caa88cacd2ff1a9e332a30", "sha256": "1ff87666699c1efbd12f6ac1e5774b03e8ffa427fbc1bfa90db0253b8eb985f4"}, "dob": {"date": "1981-07-16T08:23:18.063Z", "age": 42}, "registered": {"date": "2003-07-23T17:44:35.902Z", "age": 20}, "phone": "078 295 70 38", "cell": "079 826 99 10", "id": {"name": "AVS", "value": "756.7360.9969.72"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/women\/87.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/women\/87.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/women\/87.jpg"}, "nat": "CH"}
{"gender": "male", "name": {"title": "Mr", "first": "Fabio", "last": "Berden"}, "location": {"street": {"number": 1670, "name": "Kuppersweg"}, "city": "Geersdijk", "state": "Flevoland", "country": "Netherlands", "postcode": "4752 EK", "coordinates": {"latitude": "-51.2995", "longitude": "166.2318"}, "timezone": {"offset": "+5:30", "description": "Bombay, Calcutta, Madras, New Delhi"}}, "email": "fabio.berden@example.com", "login": {"uuid": "7cfd3044-d25c-43d0-af6b-e1d73667de8a", "username": "blackbear880", "password": "charlotte", "salt": "E5rwRznF", "md5": "ba3cb10d7412b20aebd036dfb0cc3cf5", "sha1": "93d3a46f1c54dc39f9d5735a4a1c2b3186925ea6", "sha256": "bd22abc4798b1eff04d9168dba5eb021d6427eeabad846506148b7463d205e2b"}, "dob": {"date": "1965-10-23T10:14:32.717Z", "age": 58}, "registered": {"date": "2003-02-25T05:58:56.678Z", "age": 20}, "phone": "(082) 7277281", "cell": "(06) 55254073", "id": {"name": "BSN", "value": "23564900"}, "picture": {"large": "https:\/\/randomuser.me\/api\/portraits\/men\/72.jpg", "medium": "https:\/\/randomuser.me\/api\/portraits\/med\/men\/72.jpg", "thumbnail": "https:\/\/randomuser.me\/api\/portraits\/thumb\/men\/72.jpg"}, "nat": "NL"}
123