xxxxxxxxxx
test_data = '''
{
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com",
"address": {
"street": "123 Street",
"city": "Example City",
"country": "Example Country"
},
"interests": ["programming", "reading", "travelling"]
}
'''
# Usage example:
import json
parsed_data = json.loads(test_data)
print(parsed_data['name']) # Output: John Doe
print(parsed_data['address']['city']) # Output: Example City
print(parsed_data['interests'][0]) # Output: programming
xxxxxxxxxx
var signedKey string = ""
type playlist []struct {
Group string `json:"group"`
Logo string `json:"logo"`
Name string `json:"name"`
URL string `json:"url"`
}
func getGuest() (string, error) {
body := strings.NewReader(`{"platform": "Windows NT x86 32-bit","version": "2.2","service_version": "1.2.24","branch": "master"}`)
req, err := http.NewRequest("POST", "http://www.vavoo.tv/api/box/guest", body)
if err != nil {
return "", errors.New("Bir seyler ters gitti")
}
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "VAVOO/2.2")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", errors.New("Vavoo'ya baglanilamadi!")
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
if dec == nil {
return "", errors.New("Vavoo'dan gelen veri hatali!")
}
jsonMap := make(map[string]interface{})
err = dec.Decode(&jsonMap)
if err != nil {
return "", errors.New("Json verisi bozuk!!!")
}
return jsonMap["response"].(map[string]interface{})["signed"].(string), nil
}
xxxxxxxxxx
var response = JSON.parse(responseBody);
//pm.environment.set("offerIdNumeric", response.details.quotes[0].offers[0].id);
var group = 'SALAMA';
response.details.quotes.map(quote => {
quote.offers.map(offer => {
response.push({id:offer.id,group:offer.groupId});
})
});
var filtered = response.filter((record,i) => record.group.indexOf(group) != -1);
var id = filtered[0].id;
pm.environment.set("offerIdNumeric", id);
console.log(filtered);
console.log(id)
xxxxxxxxxx
package de.rieckpil.blog;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.json.JsonContent;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@JsonTest
class PaymentResponseTest {
@Autowired
private JacksonTester<PaymentResponse> jacksonTester;
@Autowired
private ObjectMapper objectMapper;
@Test
public void shouldSerializeObject() throws IOException {
assertNotNull(objectMapper);
PaymentResponse paymentResponse = new PaymentResponse();
paymentResponse.setId("42");
paymentResponse.setAmount(new BigDecimal("42.50"));
paymentResponse.setPaymentConfirmationCode(UUID.randomUUID());
paymentResponse.setPaymentTime(LocalDateTime.parse("2020-07-20T19:00:00.123"));
JsonContent<PaymentResponse> result = jacksonTester.write(paymentResponse);
assertThat(result).hasJsonPathStringValue("$.paymentConfirmationCode");
assertThat(result).extractingJsonPathNumberValue("$.payment_amount").isEqualTo(42.50);
assertThat(result).extractingJsonPathStringValue("$.paymentTime").isEqualTo("2020-07-20|19:00:00");
assertThat(result).doesNotHaveJsonPath("$.id");
}
}