Posts

Showing posts with the label json

python google geolocation api using wifi mac

python google geolocation api using wifi mac I'm trying to use Google's API for geolocation giving wifi data to determine location. This is their intro. And this is my code @author: Keith """ import requests payload = { "considerIp": "false", "wifiAccessPoints": [ { "macAddress": "00:25:9c:cf:1c:ac", "signalStrength": -43, "signalToNoiseRatio": 0 }, { "macAddress": "00:25:9c:cf:1c:ad", "signalStrength": -55, "signalToNoiseRatio": 0 } ], 'key':'<MyAPIKey>' } r = requests.post('https://www.googleapis.com/geolocation/v1/geolocate', params=payload) print(r.text) This is the output { "location": { "lat": 32.3643098, "lng": -88.703656 }, "accuracy": 6061.0 } The request ignored all of the payload except t...

How to generate JSON examples from OpenAPI/Swagger model definition?

How to generate JSON examples from OpenAPI/Swagger model definition? I'm building a fuzzer for a REST API that has an OpenAPI (Swagger) definition. I want to test all available path from the OpenAPI definition, generate data to test the servers, analyse responses code and content, and to verify if the responses are conform to the API definition. I'm looking for a way to generate data (JSON object) from model definitions. For example, given this model: ... "Pet": { "type": "object", "required": [ "name", "photoUrls" ], "properties": { "id": { "type": "integer", "format": "int64" }, "category": { "$ref": "#/definitions/Category" }, "name": { "type": "string", "example": "doggie" }, "photoUrls": { ...

Standard JSON format for PHP

Standard JSON format for PHP I am storing data in JSON files with array of JSON objects. Right Now I am doing like [{"key1":"value1","key2":"value2"}] Is this universally accepted. ? If so which Tech Lead company supports this format . JSON is universal data format. So it is supported. In your case, however, json is incorrect as it uses single quotes. Correct json uses double quotes. More info on json.org. – u_mulder Jul 2 at 10:09 Okay ... let me correct that .. And thanks for opening the eyes of beginner – Manjunath Jidagi Jul 2 at 10:12 1 Answer 1 ...

Keeping newline n as is in JavaScript object

Keeping newline n as is in JavaScript object I want to keep string values in my insert object as is This works fine, the n is kept {insert: "erferferfnerferferf"} This {insert: "nnn"} And this becomes a problem {insert: "n"} it makes the string like this {insert: " "} I want the string to keep the "nnn" rather than becoming a bunch of new lines try using .trim() , it may solve your problem. – Raghav Garg Jul 2 at 9:49 .trim() Possible duplicate of How to escape special characters in building a JSON string? – Islam Elshobokshy Jul 2 at 9:51 JSON.stringify("nnn").slice(1, -1) – Keith ...

Very slow JSON parsing using EVReflection depending on iOS device

Very slow JSON parsing using EVReflection depending on iOS device I am obtaining a json object containing an array of objects. I am willing to parse this json using the lib EVReflection . EVReflection The operation takes a while, so I decided to monitorize the steps I'm taking, and realized the parsing of the json can take up to 20 seconds depending on the device. Using iPhone SE / iOS 11.4 it takes 4 seconds aprox. Using iPhone 5 / iOS 10.3 it takes 20 seconds aprox. I am wondering if such variation is normal just depending on devices/OS. Should I just use another lib or is there anything I can do to speed up the operation? This is the code I'm using: func getParkings(update: Bool) -> Observable<[ParkingEvo]> { if let x = parkings, !update { return Observable.just(x) } else { print("STEP 1: Calling API for parkings (NSDate())") return RxAlamofire.string(.get, PARKINGS_URL, parameters: getParameters()...

jq: Select property value using regex

jq: Select property value using regex I have the following json Object: { "foo": { "name": "Name 1", "color": "green", "something_else": { "name" : "Name 2" } }, "bar": { "name": "Something else", "color": "red" } } To get all possible parents properties of the property called "name" using jq I tried : path(recurse|select(.name? !=""))[0] And it works and give back : "foo" "foo" "bar" Now I want to apply regex to filter the property value, say I want to consider only all properties called name that have a value beginning with "Name" and followed by a number like "Name 2" , to get: name "Name 2" "foo" "foo" I tried this: path(recurse|select(.name? =~ match(/Name */)))[0] How to use mat...

Spring Boot serialize parameteried type into JSON with type id

Spring Boot serialize parameteried type into JSON with type id Spring Boot sample project: https://github.com/yejianfengblue/spring-boot-jackson-serialize-generic-type I have question in how Spring Boot serializes generic type into JSON with Jackson library. Please see my demo: Fruit is a common interface of Apple and Banana . Fruit Apple Banana BasketController has 3 RESTful API: BasketController getFruitList() List<Fruit> getFruitBasket() FruitBasket List<Fruit> getBasketOfFruit() Basket<Fruit> List<T> In BasketController , I log the JSON string written from Jackson Object Mapper and Object Writer . Please see the actual output in the comment below the log statement. BasketController BasketController.java /** <li>Object<b>Mapper</b>.writeValueAsString, @type is lost due to java type erasure. * <li>Object<b>Writer</b>.writeValueAsString, @type is kept */ @GetMapping(path = "getFruitList") public List<Fruit...

React, Firebase: Access values of JSON and also get key value

React, Firebase: Access values of JSON and also get key value I am beginner working with firebase, react. I am able to get the required data from firebase based on userEmail. But I am very confused in accessing the data. firebase.database().ref('/users').orderByChild('email').equalTo(userEmail).on('value', data => { console.log('data: ', data); }) I get the following output: data: Object { "-Lhdfgkjd6fn3AA-": Object { "email": "t5@gmail.com", "favQuote": "this is it", "firstName": "t5", "lastName": "l5", }, } Please help me how to access all values ("-Lhdfgkjd6fn3AA-" , firstname, lastname, email and favQuote) into variables like: data.firstName, data.lastName, data.key, etc . Thank you. You can get the value using: data.-Lhdfgkjd6fn3AA-.email – NullPoint...

How to read JSON file from folder project ASP.NET

Image
How to read JSON file from folder project ASP.NET I create a folder "js" inside Script folder and create a file json with array citys and i try read this file on this folder and return a list to my select view. { "cidade": [ { "Nome": "Curitiba" }, { "Nome": "São Paulo" }, { "Nome": "Rio de Janeiro" }, { "Nome": "Santa Catarina" }, { "Nome": "Rio Grande do Sul" }, { "Nome": "Acre" }, { "Nome": "Goias" } ] } My class: public class Cidade { public string Nome { get; set; } } public class Cidades { public IList < Cidade > cidades { get; set; } } And my action : public class Cidade { public string Nome { get; set; } } public class Cidades { public IList < Cidade > cidades { get; set; } } This is the error: What is...

Serializing List to JSON in C# creates backslashes in front of quotes

Serializing List to JSON in C# creates backslashes in front of quotes I am trying to serialize a List in C# and it is mostly working fine except that it creates backslashes in front of the double quotes. I have read online that this is a result from serializing the data twice and I have tried different approaches to removing the backslashes but they are not really working for me. C# code (Using NewtonSoft.Json Library): List<string> list_element_object = new List<string>(); foreach (var list_element in total_lists) { /* Code to get all of the 'element_lists' data Which is eventually used to create the 'columns' data below */ var columns = new Dictionary<string, string> { {"@type", "Element_Lists" }, {"Name", Element_List_Name }, {"Description", Element_List_Description}, {"URL", Element_URL } ...

JSON Models Django

JSON Models Django I have the following models: class Estado(models.Model): nome = models.CharField('Estado', max_length=30) uf = models.CharField('UF', max_length=2) class Cidade(models.Model): municipio= models.CharField('Municipio', max_length=50) estado = models.ForeignKey(Estado, on_delete=models.DO_NOTHING) How can i create a .json fixture for them? To add the states, I did the following: [{ "model": "comum.estado", "pk": 1, "fields": { "uf": "AC", "nome": "Acre" } }, ...etc... ] To add cities, I tried doing the following, but it did not work: [{ "model": "comum.cidade", "pk": 1, "fields": { "municipio": "Afonso Cláudio", "estado": 8 } }, ...etc... ] What should I do to fix it? 1 Answer ...

Datetime fields in json

Datetime fields in json How do we store postgres datetime objects in java pojo classes for json objects? I am trying to sort them and want to check if I should be comparing datetime or strings? Date compareTo doesn't work but strings comparTo works fine for datetime objects private Date fieldA; private Date fieldB; fieldA.compareTo(fieldB); What do you mean by Date compareTo doesn't work? It always seems to work for me. Have you got an example of two dates for which it gives an incorrect result? – Dawood ibn Kareem Jul 1 at 19:34 Date compareTo @JEE_program I find that extremely difficult to believe. Is there any possibility you have made a mistake of some kind? – Dawood ibn Kareem Jul 1 at 19:43 ...

jq array of hashes to csv

jq array of hashes to csv So I have a data source like this: { "things": [ { "thing_name": "Bestco", "thing_id": 1 }, { "thing_name": "GreatCo", "thing_id": 2 }, { "thing_name": "DressCo", "thing_id": 3 } ] } I want to get output like this: $ echo '{"things":[{"thing_name":"Bestco","thing_id":1},{"thing_name":"GreatCo","thing_id":2},{"thing_name":"DressCo","thing_id":3}]}' | jq -r '.things | map(.thing_name, .thing_id, "n") | @csv' | sed -e 's/,"$//g' -e 's/^",//g' -e 's/^"$//g' "Bestco",1 "GreatCo",2 "DressCo",3 $ Using a fake parameter seems like a hack and then needs to be clean up by sed to work. How do I do this with just jq...

NodeJS - Return a JSON from a request

NodeJS - Return a JSON from a request I am currently doing some stuffs in NodeJS and now I have the following issue: When I get a JSON Object from a HTTP Request and want to return it, it's showing "undefined" . "undefined" Here is my not working NodeJS Code: function verifyUser(uname,pword){ var options = { url: 'CENSORED', method: 'POST', headers: headers, form: {'Username':uname, 'Password':pword, 'Key':key} } request(options,function(error,response,body){ if(!error && response.statusCode == 200){ return body; } }) } var test1 = verifyUser("RobDeFlop","CENSORED"); console.log(test1); But when I replace the return with a console.log its showing me the json object. I hope someone can help me :) return console.log The function you pass to request is called by request once the response ...

JavaScript - how to get value by using a JSON ID that is in another JSON

Image
JavaScript - how to get value by using a JSON ID that is in another JSON The exercise is as follows: It is required to obtain an Arrangement with the names of clients ordered from highest to lowest by the TOTAL sum of the balances. with these javascript objects: const clients = [ { id: 1, taxNumber: '86620855', name: 'HECTOR ACUÑA BOLAÑOS'}, { id: 2, taxNumber: '7317855K', name: 'JESUS RODRIGUEZ ALVAREZ'}, { id: 3, taxNumber: '73826497', name: 'ANDRES NADAL MOLINA'}, { id: 4, taxNumber: '88587715', name: 'SALVADOR ARNEDO MANRIQUEZ'}, { id: 5, taxNumber: '94020190', name: 'VICTOR MANUEL ROJAS LUCAS'}, { id: 6, taxNumber: '99804238', name: 'MOHAMED FERRE SAMPER' } ]; and: const accounts = [ { clientId: 6, bankId: 1, balance: 15000 }, { clientId: 1, bankId: 3, balance: 18000 }, { clientId: 5, bankId: 3, balance: 135000 }, { clientId: 2, bankId: 2, balance: 5600 }, { clientId: 3, bankId: 1, bala...