39 from_json( String &&json_data, options::parse_flags_t<PolicyFlags...> ) {
41 json_details::is_string_view_like_v<String>,
42 "String type must have a be a contiguous range of Characters" );
44 ErrorReason::EmptyJSONDocument );
46 ErrorReason::EmptyJSONDocument );
49 json_details::has_json_deduced_type_v<JsonMember>,
50 "Missing specialization of daw::json::json_data_contract for class "
51 "mapping or specialization of daw::json::json_link_basic_type_map" );
52 using json_member = json_details::json_deduced_type<JsonMember>;
58 using policy_zstring_t = json_details::apply_zstring_policy_option_t<
59 ParsePolicy, String, options::ZeroTerminatedString::yes>;
62 daw::conditional_t<policy_zstring_t::is_default_parse_policy,
64 auto first = std::data( json_data );
65 auto last = daw::data_end( json_data );
66 if( first != last and last[-1] == 0 ) {
69 auto parse_state = ParseState( first, last );
71 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
73 json_details::parse_value<json_member, KnownBounds,
74 json_member::expected_type>( parse_state );
75 parse_state.trim_left( );
80 return json_details::parse_value<json_member, KnownBounds,
81 json_member::expected_type>(
115 options::parse_flags_t<PolicyFlags...> ) {
117 json_details::is_string_view_like_v<String>,
118 "String type must have a be a contiguous range of Characters" );
120 ErrorReason::EmptyJSONDocument );
122 ErrorReason::EmptyJSONPath );
124 using json_member = json_details::json_deduced_type<JsonMember>;
127 json_details::has_unnamed_default_type_mapping_v<JsonMember>,
128 "Missing specialization of daw::json::json_data_contract for class "
129 "mapping or specialization of daw::json::json_link_basic_type_map" );
131 char const *f = std::data( json_data );
132 char const *l = daw::data_end( json_data );
140 using ParseState = json_details::apply_zstring_policy_option_t<
141 ParsePolicy, String, options::ZeroTerminatedString::yes>;
143 auto parse_state = ParseState::with_allocator( f, l, a );
144 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
146 json_details::parse_value<json_member, KnownBounds,
147 json_member::expected_type>( parse_state );
148 parse_state.trim_left( );
153 return json_details::parse_value<json_member, KnownBounds,
154 json_member::expected_type>(
191 from_json( String &&json_data, std::string_view member_path,
192 options::parse_flags_t<PolicyFlags...> ) {
194 json_details::is_string_view_like_v<String>,
195 "String type must have a be a contiguous range of Characters" );
198 ErrorReason::EmptyJSONDocument );
200 ErrorReason::EmptyJSONPath );
202 ErrorReason::EmptyJSONPath );
204 using json_member = json_details::json_deduced_type<JsonMember>;
206 json_details::has_unnamed_default_type_mapping_v<JsonMember>,
207 "Missing specialization of daw::json::json_data_contract for class "
208 "mapping or specialization of daw::json::json_link_basic_type_map" );
215 using policy_zstring_t = json_details::apply_zstring_policy_option_t<
216 ParsePolicy, String, options::ZeroTerminatedString::yes>;
219 daw::conditional_t<policy_zstring_t::is_default_parse_policy,
221 auto first = std::data( json_data );
222 auto last = daw::data_end( json_data );
223 if( first != last and last[-1] == 0 ) {
227 jv = jv.find_member( member_path );
229 if constexpr( json_details::is_json_nullable_v<json_member> ) {
231 return json_details::construct_nullable_empty<
232 json_details::json_constructor_t<json_member>>( );
237 auto parse_state = jv.get_raw_state( );
238 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
240 json_details::parse_value<json_member, KnownBounds,
241 json_member::expected_type>( parse_state );
242 parse_state.trim_left( );
247 return json_details::parse_value<json_member, KnownBounds,
248 json_member::expected_type>(
264 [[nodiscard]]
constexpr auto from_json( String &&json_data,
265 std::string_view member_path ) {
267 json_details::is_string_view_like_v<String>,
268 "String type must have a be a contiguous range of Characters" );
270 return from_json<JsonMember, KnownBounds>(
271 DAW_FWD( json_data ), member_path, options::parse_flags<> );
288 Allocator
const &alloc,
289 options::parse_flags_t<PolicyFlags...> ) {
292 json_details::is_string_view_like_v<String>,
293 "String type must have a be a contiguous range of Characters" );
295 ErrorReason::EmptyJSONDocument );
297 ErrorReason::EmptyJSONDocument );
299 ErrorReason::EmptyJSONPath );
301 using json_member = json_details::json_deduced_type<JsonMember>;
303 json_details::has_unnamed_default_type_mapping_v<JsonMember>,
304 "Missing specialization of daw::json::json_data_contract for class "
305 "mapping or specialization of daw::json::json_link_basic_type_map" );
312 using ParseState = json_details::apply_zstring_policy_option_t<
313 ParsePolicy, String, options::ZeroTerminatedString::yes>;
315 auto first = std::data( json_data );
316 auto last = daw::data_end( json_data );
317 if( first != last and last[-1] == 0 ) {
321 ParseState( first, last, first, last ).with_allocator( alloc ) );
322 jv = jv.find_member( member_path );
324 if constexpr( json_details::is_json_nullable_v<json_member> ) {
326 return json_details::construct_nullable_empty<
327 json_details::json_constructor_t<json_member>>( );
332 auto parse_state = jv.get_raw_state( );
333 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
335 json_details::parse_value<json_member, KnownBounds,
336 json_member::expected_type>( parse_state );
337 parse_state.trim_left( );
342 return json_details::parse_value<json_member, KnownBounds,
343 json_member::expected_type>(
361 std::string_view member_path,
362 Allocator
const &alloc ) {
364 json_details::is_string_view_like_v<String>,
365 "String type must have a be a contiguous range of Characters" );
367 return from_json_alloc<JsonMember, KnownBounds>(
368 DAW_FWD( json_data ), member_path, alloc, options::parse_flags<> );
382 options::parse_flags_t<PolicyFlags...> ) {
383 using json_member = json_details::json_deduced_type<JsonMember>;
385 json_details::has_unnamed_default_type_mapping_v<JsonMember>,
386 "Missing specialization of daw::json::json_data_contract for class "
387 "mapping or specialization of daw::json::json_link_basic_type_map" );
389 P, Allocator>::template SetPolicyOptions<PolicyFlags...>;
391 daw::conditional_t<ParsePolicy::is_default_parse_policy,
393 auto const old_parse_state = value.get_raw_state( );
395 ParseState( old_parse_state.first, old_parse_state.last,
396 old_parse_state.class_first, old_parse_state.class_last,
397 old_parse_state.get_allocator( ) );
399 return json_details::parse_value<json_member, KnownBounds,
400 json_member::expected_type>(
434 std::string_view member_path,
435 options::parse_flags_t<PolicyFlags...> ) {
436 using json_member = json_details::json_deduced_type<JsonMember>;
438 json_details::has_unnamed_default_type_mapping_v<JsonMember>,
439 "Missing specialization of daw::json::json_data_contract for class "
440 "mapping or specialization of daw::json::json_link_basic_type_map" );
443 auto const old_parse_state = value.get_raw_state( );
445 daw::conditional_t<ParsePolicy::is_default_parse_policy,
448 ParseState( old_parse_state.first, old_parse_state.last,
449 old_parse_state.class_first, old_parse_state.class_last,
450 old_parse_state.get_allocator( ) ) );
452 jv = jv.find_member( member_path );
454 if constexpr( json_details::is_json_nullable_v<json_member> ) {
456 return json_details::construct_nullable_empty<
457 json_details::json_constructor_t<json_member>>( );
462 auto parse_state = jv.get_raw_state( );
463 return json_details::parse_value<json_member, KnownBounds,
464 json_member::expected_type>(
500 options::parse_flags_t<PolicyFlags...> ) {
502 json_details::is_string_view_like_v<String>,
503 "String type must have a be a contiguous range of Characters" );
506 ErrorReason::EmptyJSONDocument );
508 ErrorReason::EmptyJSONPath );
510 json_details::has_unnamed_default_type_mapping_v<JsonElement>,
511 "Missing specialization of daw::json::json_data_contract for class "
512 "mapping or specialization of daw::json::json_link_basic_type_map" );
513 using element_type = json_details::json_deduced_type<JsonElement>;
514 static_assert( not std::is_same_v<element_type, void>,
515 "Unknown JsonElement type." );
518 json_base::json_array<JsonElement, Container, Constructor>;
525 using policy_zstring_t = json_details::apply_zstring_policy_option_t<
526 ParsePolicy, String, options::ZeroTerminatedString::yes>;
529 daw::conditional_t<policy_zstring_t::is_default_parse_policy,
532 ParseState{ std::data( json_data ), daw::data_end( json_data ) };
534 parse_state.trim_left_unchecked( );
535#if defined( DAW_JSON_BUGFIX_FROM_JSON_001 )
537 ErrorReason::InvalidArrayStart, parse_state );
540 ErrorReason::InvalidArrayStart, parse_state );
542 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
544 json_details::parse_value_array<parser_t, KnownBounds>( parse_state );
545 parse_state.trim_left( );
550 return json_details::parse_value_array<parser_t, KnownBounds>(
592 options::parse_flags_t<PolicyFlags...> ) {
594 json_details::is_string_view_like_v<String>,
595 "String type must have a be a contiguous range of Characters" );
598 ErrorReason::EmptyJSONDocument );
600 ErrorReason::EmptyJSONPath );
602 ErrorReason::EmptyJSONPath );
604 json_details::has_unnamed_default_type_mapping_v<JsonElement>,
605 "Missing specialization of daw::json::json_data_contract for class "
606 "mapping or specialization of daw::json::json_link_basic_type_map" );
607 using element_type = json_details::json_deduced_type<JsonElement>;
608 static_assert( not std::is_same_v<element_type, void>,
609 "Unknown JsonElement type." );
612 json_base::json_array<JsonElement, Container, Constructor>;
619 using policy_zstring_t = json_details::apply_zstring_policy_option_t<
620 ParsePolicy, String, options::ZeroTerminatedString::yes>;
623 daw::conditional_t<policy_zstring_t::is_default_parse_policy,
625 auto first = std::data( json_data );
626 auto last = daw::data_end( json_data );
627 if( first != last and last[-1] == 0 ) {
631 jv = jv.find_member( member_path );
633 if constexpr( json_details::is_json_nullable_v<parser_t> ) {
635 return json_details::construct_nullable_empty<
636 json_details::json_constructor_t<parser_t>>( );
641 auto parse_state = jv.get_raw_state( );
642 parse_state.trim_left_unchecked( );
643#if defined( DAW_JSON_BUGFIX_FROM_JSON_001 )
645 ErrorReason::InvalidArrayStart, parse_state );
648 ErrorReason::InvalidArrayStart, parse_state );
650 if constexpr( ParseState::must_verify_end_of_data_is_valid ) {
652 json_details::parse_value_array<parser_t, KnownBounds>( parse_state );
653 parse_state.trim_left( );
658 return json_details::parse_value_array<parser_t, KnownBounds>(
681 json_details::is_string_view_like_v<String>,
682 "String type must have a be a contiguous range of Characters" );
684 return from_json_array<JsonElement, Container, Constructor, KnownBounds>(
685 DAW_FWD( json_data ), member_path, options::parse_flags<> );