Need help in parsing the below using reex - json

I am zero in regex and need help in parsing the value for key "access_token" from the below output.This will be later used in passing as variable for another function.
So basically the regex should only fetch
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiaXRwcm9kbW9uaXRvciIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2dpdmVubmFtZSI6IkxPS0VTSCBEVVJBSVJBSiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IlNEQ1NfSEVMUERFU0siLCJQZXJtaXNzaW9ucyI6IjkwMzAsOTAwMCw5MDI4LDkwMjcsOTAyNiw5MDI1LDkwMjQsOTAyMyw5MDIyLDkwMjEsOTAyMCw5MDE5LDkwMTgsOTAxMyw5MDEyLDkwMTEsOTAxMCw5MDA5LDkwMDgsOTAwNyw5MDA2LDkwMDUsOTAwNCw5MDAzLDkwMDIsOTAwMSw5MDI5IiwiYWlycG9ydHMiOiJTWVoiLCJjbGllbnRJUCI6IjEwLjExMS4xLjEiLCJlbnYiOiJQUk9EIiwicmVzQ2hhbm5lbElEIjoiMTkiLCJpc0FwdENsbnQiOiJUcnVlIiwiY2hrTGNuIjoiQWlycG9ydCIsIm5iZiI6MTUzODkxNDY0OSwiZXhwIjoxNTM4OTE3NjQ5LCJpc3MiOiJmbHlkdWJhaS5jb20iLCJhdWQiOiIxNDEyMDAxIn0.qYID1b5lMjFhn7fTcSX5v6K6z2YpGJwAvE4gQfVrhxo
Here is the output of my Post output
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiaXRwcm9kbW9uaXRvciIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2dpdmVubmFtZSI6IkxPS0VTSCBEVVJBSVJBSiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IlNEQ1NfSEVMUERFU0siLCJQZXJtaXNzaW9ucyI6IjkwMzAsOTAwMCw5MDI4LDkwMjcsOTAyNiw5MDI1LDkwMjQsOTAyMyw5MDIyLDkwMjEsOTAyMCw5MDE5LDkwMTgsOTAxMyw5MDEyLDkwMTEsOTAxMCw5MDA5LDkwMDgsOTAwNyw5MDA2LDkwMDUsOTAwNCw5MDAzLDkwMDIsOTAwMSw5MDI5IiwiYWlycG9ydHMiOiJTWVoiLCJjbGllbnRJUCI6IjEwLjExMS4xLjEiLCJlbnYiOiJQUk9EIiwicmVzQ2hhbm5lbElEIjoiMTkiLCJpc0FwdENsbnQiOiJUcnVlIiwiY2hrTGNuIjoiQWlycG9ydCIsIm5iZiI6MTUzODkxNDY0OSwiZXhwIjoxNTM4OTE3NjQ5LCJpc3MiOiJmbHlkdWJhaS5jb20iLCJhdWQiOiIxNDEyMDAxIn0.qYID1b5lMjFhn7fTcSX5v6K6z2YpGJwAvE4gQfVrhxo",
"token_type": "bearer",
"expires_in": 2999,
"refresh_token": "65be41084c0b4adeaeec9725cb2e6240",
"audience": "1412001",
"displayName": "Lokesh",
"userId": "testuser78",
"rolesandpermission": "HELPDESK:9030,9000,9028,9027,9026,9025,9024,9023,9022,9021,9020,9019,9018,9013,9012,9011,9010,9009,9008,9007,9006,9005,9004,9003,9002,9001,9029",
"resChannelID": "19",
"Client": "FYC",
"isAptClnt": "True",
"scope": "apt:FYC env:PROD role:HELPDESK",
".issued": "Sun, 07 Oct 2018 12:17:29 GMT",
".expires": "Sun, 07 Oct 2018 13:07:29 GMT"
}

Simple PCRE look like
\"access_token\":.\"(.+?)\"
And you will get your token in fast captured group
You can practice with this regex on this website
https://regex101.com/

Related

Strip Content From a Data Object in Vuejs

I have a JSON data and I would like to strip "description" into two different data objects.
JSON FILE:
{
"#attributes": {
"version": "2.0"
},
"channel": {
"title": "Rust News",
"description": "The latest news posts from Rust",
"lastBuildDate": "Thu, 07 Jul 2022 07:00:00 Z",
"item": [
{
"guid": "https:\/\/rust.facepunch.com\/news\/july-2022-update\/",
"link": "https:\/\/rust.facepunch.com\/news\/july-2022-update\/",
"title": "July Update",
"description": "<img src=\"https:\/\/files.facepunch.com\/paddy\/20220705\/july_2022_header.jpg\"><br\/>Combat balance, faster load times, chat filter and much more!\u00a0\u00a0",
"pubDate": "Thu, 07 Jul 2022 07:00:00 Z"
},
{
"guid": "https:\/\/rust.facepunch.com\/news\/community-update-243\/",
"link": "https:\/\/rust.facepunch.com\/news\/community-update-243\/",
"title": "Community Update 243",
"description": "<img src=\"https:\/\/files.facepunch.com\/errn\/1b1311b1\/FTTfqglWQAMxkzD.jpg\"><br\/>Custom desk mats, Mars monuments, thoughtful poetry, and more!",
"pubDate": "Wed, 15 Jun 2022 12:00:00 Z"
},
...
I would like to fetch two objects from the same "description" string:
First Object:
<img src="https://files.facepunch.com/paddy/20220705/july_2022_header.jpg">
Second Object:
Combat balance, faster load times, chat filter and much more!
Here is my Script file:
data() {
return {
items: []
}
},
mounted() {
this.axios.get("./api/json.php").then(response => {
this.items = response.data.channel.item;
});
}
how would I assign item.image and item.description string separately?
Or perhaps there is a way to do it from the server-side since the JSON is generated with a PHP from an XML file
Any help with this would be much appreciated!

Parsing JSON data in flutter that has a null key

I have a json data that I used a website to parse(this is the site: https://javiercbk.github.io/json_to_dart/ ) but I got an error that the model was not correct and that is because my json data contains a list that has a list and in that list, another list that contains the keys and their values but there is a key which is null in that list..I put the json data below for better understanding..My question is, "is there any way that I can create a model and skip over the null key and work with the other available keys and values?"
{
"result": {
"newsfeed": [
[
null,
{
"author": "5f177c2139e3390017e71c70",
"userTag": "",
"text": "try this one",
"video": "",
"image": "",
"createdAt": "Wed Sep 16 2020 09:28:00 GMT+0000 (Coordinated Universal Time)",
"name": "",
"campus": ""
}
],
[
null,
{
"author": "5f177d2739e3390017e71c71",
"userTag": "bigjo",
"text": "yooooo",
"video": "",
"image": "",
"createdAt": "Wed Sep 16 2020 09:28:00 GMT+0000 (Coordinated Universal Time)",
"name": "",
"campus": "Bells University Of Technology"
}
]
]
}
}
Well you can assign some other value to it instead of null.
x['result']['newsfeed'].forEach((element){
element[0] = element[1]; //or any other object
}
This might not be the best way to do it though.
I also just had such issues. You can use QuickType to generate the mapping code for you based on the JSON input.
I am using factory for JSON decoding and for optional values the line would be something like
taskPic: parsedJson["taskPic"] == null ? null : parsedJson['taskPic'],

update unix timestamps (in ms) with their human-readable equivalents in a JSON value

I have a file with some epoch date (with millisecondes) coded inside.
I would like to parse the file to convert the epoch into human readable date format.
This is what the content of the file looks like :
{
"Date": "1555095683495",
"read": "1"
},
{
"Date": "1555578329532",
"read": "1"
},
I tried to convert the date by using the commande date with the use into sed but dont get it working correctly.
=> case 1 : the epoch date is replaced but date is not executed.
$ cat myfile.json | sed -e "s/\([0-9]\{13,\}\)/date -d #\1/g"*
{
"Date": "date -d #1555095683495",
"read": "1"
},
{
"Date": "date -d #1555578329532",
"read": "1"
}
==> case 2: epoch date is replace by a executed command of date but it take #1 as value and not the good one...
$cat myfile.txt | sed -e "s/[0-9]\{13,\}/$(date -d #\1)/g"
{
"Date": "jeu 01 jan 1970 01:00:01 CET",
"read": "1"
},
{
"Date": "jeu 01 jan 1970 01:00:01 CET",
"read": "1"
}
Any help appreciated to get it working correctly.
I also presume the value has to be divided by 1000 to get the milliseconds away but dont see how to get both working.
With JQ, convert each timestamp to a number, divide the result by 1000 to get a value that date manipulation builtins could understand, and feed it to strflocaltime to get a human-readable date string.
$ jq '.[].Date |= (tonumber / 1000 | strflocaltime("%c %Z"))' file
[
{
"Date": "Fri Apr 12 22:01:23 2019 +03",
"read": "1"
},
{
"Date": "Thu Apr 18 12:05:29 2019 +03",
"read": "1"
}
]

Any way to reformat "json" file so I can extract the data?

A colleague of mine sent this file over to me asking me to extract the data into a database.... issue is, it is not formatted correctly. (It is supposed to be a json file... even sent as orders.json).
Here is the file contents (The other files are much larger, this is just a snippet):
[
"Buyer: Jane Doe ",
[
"jane Doe",
"Street Here",
"State, ZIP",
"Phone : 8888888"
],
"Ship By: Wed, Oct 11, 2017 to Thu, Oct 12, 2017",
"Deliver By: Mon, Oct 16, 2017 to Thu, Oct 19, 2017",
"Shipping Service: Standard",
[
[
"Product name",
"SKU: 99999999999",
"ASIN: 999999999",
"Condition: New",
"Listing ID: 99999999999",
"Order Item ID: 9999999999",
"Customizations:",
"Size: 16 Inches",
"Monogram Letters: BSA",
"Color: Unpainted (goes out in 48 hrs)"
]
],
"A",
"Wed, Oct 4, 2017, 8:03 PM PT",
"114-7275553-4341048",
[
"1"
]
]
I believe I will have to go through this slowly and use unnecessary methods to get this to look nice and work... unless I am missing something?
As of right now I can't really access the data in a efficient way.

How does DROPBOX response (JSON) data look like?

Good day, does anyone know typical JSON response data, when accessing a file? I am more interested in whether or not one can check if a response object is a file or a directory!
Thanx mates
This is a common JSON answer, when you try to get information about file/folder.
You can see more information about request here
if is_dir is true, it's a folder.
{
"size": "225.4KB",
"rev": "35e97029684fe",
"thumb_exists": false,
"bytes": 230783,
"modified": "Tue, 19 Jul 2011 21:55:38 +0000",
"client_mtime": "Mon, 18 Jul 2011 18:04:35 +0000",
"path": "/Getting_Started.pdf",
"is_dir": false,
"icon": "page_white_acrobat",
"root": "dropbox",
"mime_type": "application/pdf",
"revision": 220823
}