How to convert JSON response to tables in Power BI - json

I am the task of consuming from a webservice some data by means of REST, for the consumption of data from Power BI I have used as a source a blank query where later I have added in the advanced editor the following query:
let
url = "http://*********",
headers= [#"Content-Type"="application/json"],
postData = Text.ToBinary("{""token"":""*************""}"),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),
jsonResponse = Json.Document(response)
in
jsonResponse
As an answer I have clearly obtained a JSON file which is composed as follows:
{'result':'1',
'message':'Successful Operation',
'data':[
{'idActivity':'1001',
'organization':'ABC-001' ,
'date':'6/10/2022 2:34:04 PM',
'lat':'57.3497300',
'lng':'-90.3929000',
'status':'0',
'company':'382',
'tag':'0'},
{'idActivity':'1002',
'organization':'DEF-002',
'date':'6/10/2022 2:21:15 PM',
'lat':'83.6718200',
'lng':'-23.3464000',
'status':'0',
'company':'932',
'tag':'0'}]}
I would like to know if there is a way to convert this JSON file to tables and then be able to represent the information in power bi visuals?

Click the parse JSON button. That should parse it automatically. You might need to replace your single quotes with double quotes ("). Your sample JSON worked for me using parse JSON when I did that.

Related

Write JSON to a file in pretty print format in Django

I need to create some JSON files for exporting data from a Django system to Google Big Query.
The problem is that Google BQ imposes some characteristics in the JSON file, for example, that each object must be in a different line.
json.dumps writes a stringified version of the JSON, so it is not useful for me.
Django serializes writes better JSON, but it put all in one line. All the information I found about pretty-printing is about json.dumps, which I cannot use.
I will like to know if anyone knows a way to create a JSON file in the format required by Big Query.
Example:
JSONSerializer = serializers.get_serializer("json")
json_serializer = JSONSerializer()
data_objects = DataObject.objects.all()
with open("dataobjects.json", "w") as out:
json_serializer.serialize(data_objects, stream=out)
json.dumps is OK. You have to use indent like this.
import json
myjson = '{"latitude":48.858093,"longitude":2.294694}'
mydata = json.loads(myjson)
print(json.dumps(mydata, indent=4, sort_keys=True))
Output:
{
"latitude": 48.858093,
"longitude": 2.294694
}

extract a concrete part of a value from a Response to a new string Groovy script

I'm kinda new in groovy and I need help
I need to write a groovy script to transform or else extract a concrete value from a Json Response to a new string Groovy script.
and the groovy script I used is this one :
responseJson = testRunner.testCase.getTestStepByName("Test Scenario").getPropertyValue("response")
parsedResponse = slurper.parseText(responseJson)
log.info(parsedResponse["items"]["/ticket_id"])
My generated string response from the groovy script I use looks like this:
/ticket_id":"{\"isTodo\":false,\"items\":[[\"WhatIwantToExtract\",\"\",\"url.com:blablabla_qc_vpc-11:Machine:data-da-data\",timestamp]]}
The response is correct in fact but I just want to extract a piece of this
The data I wanted to extract is labeled above as " WhatIwantToExtract " without the commas.
I solved it
def regexResult = (parsedResponse["items"][0][0])

Read json file in jsr223 sampler in jmeter and extract data

import com.jayway.jsonpath.JsonPath
def idCSV = new File('id.csv')
def index = [fileOne.json, fileTwo.json]
def jsonString
index.each { file ->
jsonString = ________
def ids = JsonPath.read(jsonString, '$..id')
ids.each { id ->
idCSV << id << newLine
}
}
How to fill the jsonString = ____, so that I can json file into string and parse the string to extract ids and some information from the json string.
And I don't to do it in http request-> GET-> file format.
Previously i have extraced jsonString from http response and it worked well now I want to do it this way.
Use JsonSlurper:
def jsonString = new groovy.json.JsonSlurper().parseText(new File("json.txt").text)
My expectation is that you're looking for File.getText() function
jsonString = file.text
I have no full vision why do you need to store the values from JSON in a CSV file, however there is an alternative way of achieving this which doesn't require scripting as your approach will work with 1 concurrent thread only, if you will add more users attempting writing into the same file - you'll run into a race condition :
You can read the files from the folder into JMeter Variables via Directory Listing Config
The file can be read using HTTP Request sampler
The values cane be fetched using JSON Extractor, they will be automatically stored into JMeter Variables so you will able to use them later on
If you need the values to be present in the file (although I wouldn't recommend this approach cause it will cause massive disk IO and potentially can run your test) you can go for the Flexible File Writer

Json Parsing in Mirth OR Json in Mirth OR HL7 to JSON in Mirth

I want to use JSON as input of mirth channel and output like details Save in db or Create HL7 message.
In short Input as JSON Parse it and output as any format.
var object = {};
//Create JSON Object from HL7 Message.
object.mrn = msg['PID']['PID.3']['PID.3.1'].toString();
object.firstName = msg['PID']['PID.5']['PID.5.2'].toString();
object.lastName = msg['PID']['PID.5']['PID.5.1'].toString();
object.dob = msg['PID']['PID.7']['PID.7.1'].toString();
object.ssn = msg['PID']['PID.19']['PID.19.1'].toString();
//Create string from JSON Object.
var objjson = JSON.stringify(object);
logger.info(objjson);
//Create Json Object From JSON string.
var tt = JSON.parse(objjson);
Output
{"mrn":"1001","firstName":"COLLEEN","lastName":"OHALLAHAN","dob":"19850704","ssn":"123456789"}
HL7Message Sample
MSH|^~\&|ADT1|SHM|SHMADT|SHM|200812091126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.5|
EVN|A01|200812091126||
PID|1|1001|1001^5^M11^ADT1^MR^SHM||OHALLAHAN^COLLEEN^^||19850704|F||2106-3|1200 N ELM STREET^^NEWPORT BEACH^CA^92660-1020^US^H|OC|(949) 555-1234|(949) 555-5678||S||PATID1001^2^M10^ADT1^AN^A|123456789|U1234567^CA|
NK1|1|OHALLAHAN^BRITTANY^M|SIS^SISTER||||N^NEXT-OF-KIN
PV1|1|I|2000^2012^01||||001122^ZOIDBERG^JOHN^|||SUR||||1|A0|
I was parsing through this page, and found your code Rikin patel. Actually when You create object and display it, it may appear in the console as a JSON data, when when you look your output it will be the normal XML driven format. But instead of the object when you use msg as below:
msg = JSON.stringify(object); //converting msg into JSON object
logger.info("json data:" + msg); //displaying the JSOn message
You will find the data being modified in the output.
As Per #Debugger, If some one want json file as input/Source then try this solution.
Mirth channel
Inbound Datatype as delimited text
Outbound DataType as Javascript
Make JavaScript Type of Destination and Write below code in Transformer:
//Create Json Object From JSON string.
var objJson = JSON.parse(messageObject.getRawData());
logger.info(objJson.propertyName);
Input:
{"mrn":"1001","firstName":"COLLEEN","lastName":"OHALLAHAN","dob":"19850704","ssn":"123456789"}
Output:
logger.info(objJson.firstName);
COLLEEN
Note:
Use connectorMessage.getRawData() instead of messageObject.getRawData() for Mirth 3.0+ version.
To receive JSON as Input in mirth channel, set inbound datatype as delimited text and in channel pre processor create Json object from received message and return the json object.
use the json object to get the details and store in some variables and use DB writer to save in db.
To build hl7 message, mirth provides few functions such as createSegment(seg name, index) to easily build your own hl7 message.

Date format in json for mobile backend

I am using App42 for my mobile backend. I need to put date field in my JSON that I am saving and further do a query on it for date search. I am not able to find it in document. Can anybody please let me know what is the required date format to do this?
You are not mentioned that which SDK you are using.
I am posting an Android sample code for date search in App42 json storage.
String yourDate = Util.getUTCFormattedTimestamp();
JSONObject jsonData = new JSONObject();
jsonData.put("name", "sachin");
jsonData.put("DOB", yourDate);
// Inserting json document.
Storage storageObj = storage.insertJSONDocument("dbName", "collectionName", jsonData);
System.out.println(storageObj);
// building query.
Query query = QueryBuilder.build("DOB", yourDate, Operator.EQUALS);
// find documents by query.
Storage result = storage.findDocumentsByQuery("dbName", "collectionName", query);
System.out.println(result);