• Complain

Jeff Friesen [Jeff Friesen] - Java XML and JSON: Document Processing for Java SE

Here you can read online Jeff Friesen [Jeff Friesen] - Java XML and JSON: Document Processing for Java SE full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2019, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Jeff Friesen [Jeff Friesen] Java XML and JSON: Document Processing for Java SE
  • Book:
    Java XML and JSON: Document Processing for Java SE
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2019
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Java XML and JSON: Document Processing for Java SE: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Java XML and JSON: Document Processing for Java SE" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Use this guide to master the XML metalanguage and JSON data format along with significant Java APIs for parsing and creating XML and JSON documents from the Java language. New in this edition is coverage of Jackson (a JSON processor for Java) and Oracles own Java API for JSON processing (JSON-P), which is a JSON processing API for Java EE that also can be used with Java SE. This new edition of Java XML and JSON also expands coverage of DOM and XSLT to include additional API content and useful examples.
All examples in this book have been tested under Java 11. In some cases, source code has been simplified to use Java 11s var language feature. The first six chapters focus on XML along with the SAX, DOM, StAX, XPath, and XSLT APIs. The remaining six chapters focus on JSON along with the mJson, GSON, JsonPath, Jackson, and JSON-P APIs. Each chapter ends with select exercises designed to challenge your grasp of the chapters content. An appendix provides the answers to these exercises.
What Youll Learn
  • Master the XML language
  • Create, validate, parse, and transform XML documents
  • Apply Javas SAX, DOM, StAX, XPath, and XSLT APIs
  • Master the JSON format for serializing and transmitting data
  • Code against third-party APIs such as Jackson, mJson, Gson, JsonPath
  • Master Oracles JSON-P API in a Java SE context

Who This Book Is For
Intermediate and advanced Java programmers who are developing applications that must access data stored in XML or JSON documents. The book also targets developers wanting to understand the XML language and JSON data format.

Jeff Friesen [Jeff Friesen]: author's other books


Who wrote Java XML and JSON: Document Processing for Java SE? Find out the surname, the name of the author of the book and a list of all author's works by series.

Java XML and JSON: Document Processing for Java SE — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Java XML and JSON: Document Processing for Java SE" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Jeff Friesen 2019
Jeff Friesen Java XML and JSON https://doi.org/10.1007/978-1-4842-4330-5_10
10. Extracting JSON Values with JsonPath
Jeff Friesen
(1)
Dauphin, MB, Canada

XPath is used to extract values from XML documents. JsonPath performs this task for JSON documents. Chapter introduces you to JsonPath.

Note

If youre unfamiliar with XPath, I recommend that you read Chapter before reading this chapter. JsonPath was derived from XPath.

What Is JsonPath?

JsonPath is a declarative query language (also known as a path-expression-syntax) for selecting and extracting a JSON documents property values . For example, you can use JsonPath to locate "John" in {"firstName": "John"} and return this value. JsonPath is based on XPath 1.0.

JsonPath was created by Stefan Goessner ( http://goessner.net ). Goessner also created JavaScript-based and PHP-based implementations of JsonPath. For complete documentation, check out Goessners website ( http://goessner.net/articles/JsonPath/index.html ).

Swedish software company Jayway ( www.jayway.com ) subsequently adapted JsonPath to Java. Their Java version of JsonPath is the focus of this chapter. You will find complete documentation on Jayways implementation of JsonPath at http://github.com/jayway/JsonPath .

Learning the JsonPath Language

JsonPath is a simple language with various features that are similar to their XPath counterparts . This language is used to construct path expressions.

A JsonPath expression begins with the dollar sign ( $ ) character, which refers to the root element of a query. The dollar sign is followed by a sequence of child elements, which are separated via dot ( . ) notation or via square bracket ( [] ) notation. For example, consider the following JSON object:
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address":
{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers":
[
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
]
}
The following dot notation-based JsonPath expression extracts, from the previous anonymous JSON object, the phone number ( 212 555-1234 ) thats assigned to the number field in the anonymous JSON object, which is assigned to the first element in the phoneNumbers array:
$.phoneNumbers[0].number

The $ character represents the anonymous root JSON object. The leftmost dot character separates the object root from the phoneNumbers property name. The [0] syntax identifies the first element in the array assigned to phoneNumbers .

The first array element stores an anonymous object consisting of "type": "home" and "number": "212 555-1234" properties. The rightmost dot character accesses this objects number child property name, which is assigned the value 212 555-1234 . This value is returned from the expression.

Alternatively, I could specify the following square bracket notation to extract the same phone number:
$['phoneNumbers'][0]['number']
The Jayway documentation identifies $ as an operator and also identifies several other basic operators. Table describes these operators.
Table 10-1

JsonPath Basic Operators

Operator

Description

$

The root element to query. This operator starts all path expressions. Its equivalent to XPaths / symbol.

@

The current node being processed by a filter predicate. Its equivalent to XPaths . symbol.

*

Wildcard. Available anywhere a name or numeric value is required.

..

Deep scan (also known as recursive descent). Available anywhere a name is required. Its equivalent to XPaths // symbol.

. name

Dot-notated child. The dot is equivalent to XPaths / symbol.

[' name ' (, ' name ')]

Bracket-notated child or children.

[ number (, number )]

Array index or indexes.

[ start : end ]

Array slice operator.

[?( expression )]

Filter operator. The expression must evaluate to a Boolean value. In other words, its a predicate.

The Jayway documentation also identifies several functions that can be invoked at the tail end of a paththe input to a function is the output of the path expression; the function output is dictated by the function itself. Table describes these functions.
Table 10-2

JsonPath Functions

Function

Description

min()

Return the minimum value (as a double ) in an array of numbers.

max()

Return the maximum value (as a double ) in an array of numbers.

avg()

Return the average value (as a double ) of an array of numbers.

stddev()

Return the standard deviation value (as a double ) of an array of numbers.

length()

Return the length (as an int ) of an array.

Finally, the Jayway documentation identifies various operators for filters, which use predicates (Boolean expressions) to restrict returned lists of items . Predicates can use the filter operators in Table to determine equality, match regular expressions, and test for inclusion.
Table 10-3

JsonPath Filter Operators

Operator

Description

==

Return true when the left operand equals the right operand. Note that is not equal to '1' (i.e., number and string are two different things).

!=

Return true when the left operand doesnt equal the right operand.

<

Return true when the left operand is less than the right operand.

<=

Return true when the left operand is less than or equal to the right operand.

>

Return true when the left operand is greater than the right operand.

>=

Return true when the left operand is greater than or equal to the right operand.

=~

Return true when the left operand matches the regular expression specified by the right operand; for example, [?(@.name =~ /foo.*?/i)] .

in

Return true when the left operand exists in the right operand; for example, [?(@.grade in ['A', 'B'])] .

nin

Return true when the left operand doesnt exist in the right operand.

subsetof

Return true when the left operand (an array) is a subset of the right operand (an array); for example, [?(@.sizes subsetof ['S', 'M', 'L'])] .

size

Return true when the size of the left operand (an array or string) matches the right operand (an integer).

empty

Return true when the left operand (an array or string) is empty and the right operand is true , or return true when the left operand is not empty and the right operand is false .

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Java XML and JSON: Document Processing for Java SE»

Look at similar books to Java XML and JSON: Document Processing for Java SE. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Java XML and JSON: Document Processing for Java SE»

Discussion, reviews of the book Java XML and JSON: Document Processing for Java SE and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.